Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have an 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.

1 Answer

0 votes
by (62.9k points)

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");

I hope this helps!

For further knowledge on Selenium, go for Selenium tutorial or Selenium training course by Intellipaat.

Browse Categories

...