6

I need to set value to primefaces or JSF selectOneMenu using webdriver.

I am able to achieve this using index but could not set value directly.

The following code is working with Index:

driver.findElement(By.name("LNSYNDGLP0_SL_CCY_editableInput")).click();
driver.findElement(By.xpath("//div[@id='LNSYNDGLP0_SL_CCY_panel']/ul/li[7]")).click();

Could anybody please suggest a way to achieve setting value to selectonemenu using Selenium webdriver?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Naresh Kavala
  • 183
  • 1
  • 6
  • 17

1 Answers1

3

You can use the [text()='item value'] selector in XPath to select the element by its node value.

driver.findElement(By.xpath("//div[@id='LNSYNDGLP0_SL_CCY_panel']/ul/li[text()='item value']")).click();
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Great! I found that the xpath needed a little tweaking so in my case it was: `driver.findElement(By.xpath("//*[@id='LNSYNDGLP0_SL_CCY_panel']/div/ul/li[text()='item value']")).click();` – Nicolaj Schweitz Feb 03 '15 at 13:39