0
votes

I have tried all the possible things. also, tried searching over tried different combinations and variations. I can get the element clicked which opens the dropdown. but i am not able to select an option in it. I tried with actions, sendkeys, keys.down/enter and multiple things as well. however, it didn't help. That's the only thing I am stuck on.

//selecting office

1.driver.findElement(By.id("DG5QEPn")).click();

Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.xpath("//*[@id="DG5QEPn"]/div/div/div1/div1"))).click();

driver.findElement(By.id("DG5QEPn")).click();

driver.findElement(By.id("DG5QEPn")).sendKeys("RTP HQ"); driver.findElement(By.id("DG5QEPn")).sendKeys(Keys.Down); driver.findElement(By.id("DG5QEPn")).sendKeys(Keys.Enter);

Html- In the below image.

enter image description here

2

2 Answers

2
votes

You should enumerate through all of the options then click on the one you want. Take a look at this.

EDIT

The easiest way that I have found was to do something along the lines of:

el = driver.find_element_by_id('id_of_select')
for option in el.find_elements_by_tag_name('option'):
    if option.text == 'The Options I Am Looking For':
        option.click() # select() in earlier versions of webdriver
        break
0
votes

Below code worked for me

WebElement selectMyElement = driver.findElement(this.getObject(By.Id("Id of Your DropDown"))); selectMyElement.click();

Actions keyDown = new Actions(driver); keyDown.sendKeys(Keys.chord(Keys.DOWN, Keys.DOWN, Keys.ENTER)).perform();