How to set “value” to input web element using sele

2019-04-19 04:10发布

I have element in my code that looks like this:

<input id="invoice_supplier_id" name="invoice[supplier_id]" type="hidden" value="">

I want to set its value, so I created a web element with it's xpath:

 val test = driver.findElements(By.xpath("""//*[@id="invoice_supplier_id"]"""))

but now I dont see an option to set the value...

3条回答
小情绪 Triste *
2楼-- · 2019-04-19 04:30

Use findElement instead of findElements

driver.findElement(By.xpath("//input[@id='invoice_supplier_id'])).sendKeys("your value");

OR

driver.findElement(By.xpath("//input[@id='invoice_supplier_id'])).setAttribute("value", "your value")

OR

driver.findElement(By.id("invoice_supplier_id")).setAttribute("value", "your value");

Hope it will help you :)

查看更多
Evening l夕情丶
3楼-- · 2019-04-19 04:30

As Shubham Jain stated, this is working to me: driver.findElement(By.id("invoice_supplier_id")).sendKeys("value"‌​, "new value");

查看更多
小情绪 Triste *
4楼-- · 2019-04-19 04:34
driver.findElement(By.id("invoice_supplier_id")).setAttribute("value", "your value");
查看更多
登录 后发表回答