3

I could not manage to select the next drop down item through the locator of the selected item. My intention is to test a site for different languages through the drop down. Sending keyboard down arrow activates the scroll bar in the drop down. Could anyone please help on this ?

driver.findElement(By.xpath(".//*[@id='trigger']/div/paper-input/paper-input-container")).click();
    Thread.sleep(1000);
    driver.findElement(By.xpath(".//*[@id='langList']//paper-item//.[@tabindex=\"0\"]")).click();
    Thread.sleep(1000);
    driver.findElement(By.xpath(".//*[@id='langList']//paper-item//.[@tabindex=\"0\"]")).sendKeys(Keys.ENTER, Keys.ARROW_DOWN);

2 Answers 2

2

I was going to write out some examples, but remembered Dave Haeffner had already covered this in his elemental selenium series.

You can find the great write-up of that here: How To Select from a Dropdown in Selenium

I will mention one thing though. You should make a great effort at never using implicit waits (Thread.sleep()). They do not make for clear exception errors unless they are handled well, and will slow down your tests greatly. Identify what you are waiting on, and create an explicit wait. If you need more information on creating those, I can go into more detail.

Sign up to request clarification or add additional context in comments.

Comments

1

Thanks a lot. It works now with the following code:

driver.findElement(By.xpath(".//*[@id='trigger']/div/paper-input/paper-input-container")).click();
    Thread.sleep(1000);
    driver.findElement(By.cssSelector(".style-scope.making-language-selector.iron-selected.x-scope.paper-item-0")).click();

    driver.findElement(By.cssSelector(".style-scope.making-language-selector.iron-selected.x-scope.paper-item-0")).sendKeys(Keys.ARROW_DOWN, Keys.ENTER);

1 Comment

StackOverflow really needs to change the rep needed to add comments lower than 50.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.