How to populate drop down when it is built using an input tag using java and selenium How to populate drop down when it is built using an input tag using java and selenium selenium selenium

How to populate drop down when it is built using an input tag using java and selenium


You are trying to click/ select the item in the drop down correct?Do the drop down items have unique id's? If so you should be able to just pass it the specific xpath id.

I personally use Css to find elements, in that case it would be

driver.find_element(By.CSS_SELECTOR,'#combo-1731-trigger-picker').click()driver.find_element(By.CSS_SELECTOR, '#combo-1731-inputEl > nth:child(x)').click()

where x = the count of your drop down item.

or if they have unique id's then use

driver.find_element(By.CSS_SELECTOR, '#theUniqueIdGoesHere').click()

I wrote a whole weeks worth of tests, using xpath selectors, it was painful day to day running the test and watching it fail. Going back and changing everything to Css selectors has saved me many head aches since I started writing Auto tests.

Edit: you could try the following,

driver.findElement(By.linkText("Your Links Text Here")).click();

This will only work if each links text is unique as well, if not it will select the first one it finds.

If these work for you would you mind accepting my answer?