java - How to select options provided in a textbox using Selenium -
link: http://www.bbc.com/weather/
scenario: type "reading" on find forecast text box. shows 2 options. how select 1 option using selenium webdriver?
i using following command type "reading"
driver.findelement(by.id("locator-form-search")).sendkeys("reading");
use following locator click on first element (first suggestion displayed after typing):
driver.findelement(by.cssselector("div[class='locator-suggestions locator-suggestions-default'] li:nth-child(1)")).click();
similarly can click on other element changing locator. example select second element:
driver.findelement(by.cssselector("div[class='locator-suggestions locator-suggestions-default'] li:nth-child(2)")).click();
just add here, may need wait elements/suggestions (which you're trying select) visible, before trying click on those. use/search appropriate wait method testing. so,
- first need type "reading" in field doing using
driver.findelement(by.cssselector("input#locator-form-search")).sendkeys("reading");
- then wait element visible
- then try above mentioned code select desired element.
hope helps.
Comments
Post a Comment