Java – Selecting value from autosuggestion box using selenium webdriver

javaseleniumselenium-webdriver

I am trying to automate wikipedia – search text field – using selenium webdriver.

I want to send text "kin" into it and select value "kinu" from the autopopulated list.

HTML for input box:input type="search" dir="auto" accesskey="F" autofocus="autofocus" size="20" name="search" id="searchInput" results="10" autocomplete="off" list="suggestions"

is there any way to traverse through the list by using key down event and select value "kinu" from the list?

enter image description here

From firebug , i can see that HTML for this field "kinu" is
<"option value="Kinu">.enter image description here

so i tried finding the value using xpath
WebElement el1= driver.findElement(By.xpath("//option[@value='kinu']"));
but i am not able to find it. is there any other way to get this ?

Best Answer

You MAY need the driver to click the element first (auto complete box) then use the following:

driver.findElement(By.xpath("//input[contains(@id, 'searchInput')]")).sendKeys("Kinu" + Keys.ENTER);
Related Topic