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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -