How to handle AutoSearch completion using Selenium webdriver

Swati Jha

I am running Selenium Web-driver using JAVA and facing an issue with auto-suggest input text field. When I enter a String "books" in the text field, an option would show up. Then I want to click or select the input populated on the auto suggest menu.

Below is the code:

WebDriver driver = new FirefoxDriver();

driver.get("http://www.amazon.com/");

driver.findElement(By.id("twotabsearchtextbox")).sendKeys("books");

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("gwcswTooltip")));

List<WebElement> findElements = driver.findElements((By.id("gwcswTooltip").name("books on")));

for (WebElement webElement : findElements)
{
  System.out.println(webElement.getText());
}
Hemanth

You need to just pick the right locator.

Add the following line

List<WebElement> findElements = driver.findElements((By.xpath("//div[@id='srch_sggst']/div")));

instead of

List<WebElement> findElements = driver.findElements((By.id("gwcswTooltip").name("books on")));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to handle popup window using selenium webdriver with Java

From Dev

How to handle the new window in Selenium WebDriver using Java?

From Dev

How to handle Pop-up in Selenium WebDriver using Java

From Dev

How to handle calendar popup using Selenium WebDriver with Java?

From Dev

How to Handle HTTP Basic Auth headers in Selenium Webdriver using Java ?

From Dev

How to handle authentication popup in Chrome with Selenium WebDriver using Java

From Dev

How to handle dynamic text (Success and Failure text)using Selenium WebDriver

From Dev

How to handle hidden webelement in selenium webdriver with java

From Dev

How to Handle pop ups in selenium Webdriver

From Dev

How to handle a web element getting removed from DOM using Selenium Webdriver?

From Dev

How to handle download pop-up in firefox, while downloading excel using Selenium Webdriver

From Dev

how to handle create account -button which has href link (anchor tag) using selenium webdriver in java

From Dev

How to handle Chrome application authentication alert using Selenium Webdriver and C#

From Dev

How to handle Javascript Alert/pop up window in selenium webdriver

From Dev

How to handle Javascript Alert/pop up window in selenium webdriver

From Dev

How to handle Firefox Upload File window with Selenium WebDriver - Java

From Java

How to open a new tab using Selenium WebDriver?

From Dev

How to double click on an element using Selenium Webdriver

From Dev

How to perform load testing using Selenium WebDriver?

From Dev

How to wait for an element NOT to be clickable using Selenium Webdriver?

From Dev

How to implement PhantomJS with Selenium WebDriver using java

From Dev

How to launch Safari with Selenium WebDriver using Java

From Dev

How to avoid the hidden classes using selenium webdriver

From Dev

How to wait for an element NOT to be clickable using Selenium Webdriver?

From Dev

how to click the div in css using selenium webdriver

From Dev

How to perform load testing using Selenium WebDriver?

From Dev

How to launch Safari with Selenium WebDriver using Java

From Dev

How to check the checkboxes using the Selenium Java WebDriver?

From Dev

Using Selenium Webdriver how to retrive date text

Related Related

  1. 1

    How to handle popup window using selenium webdriver with Java

  2. 2

    How to handle the new window in Selenium WebDriver using Java?

  3. 3

    How to handle Pop-up in Selenium WebDriver using Java

  4. 4

    How to handle calendar popup using Selenium WebDriver with Java?

  5. 5

    How to Handle HTTP Basic Auth headers in Selenium Webdriver using Java ?

  6. 6

    How to handle authentication popup in Chrome with Selenium WebDriver using Java

  7. 7

    How to handle dynamic text (Success and Failure text)using Selenium WebDriver

  8. 8

    How to handle hidden webelement in selenium webdriver with java

  9. 9

    How to Handle pop ups in selenium Webdriver

  10. 10

    How to handle a web element getting removed from DOM using Selenium Webdriver?

  11. 11

    How to handle download pop-up in firefox, while downloading excel using Selenium Webdriver

  12. 12

    how to handle create account -button which has href link (anchor tag) using selenium webdriver in java

  13. 13

    How to handle Chrome application authentication alert using Selenium Webdriver and C#

  14. 14

    How to handle Javascript Alert/pop up window in selenium webdriver

  15. 15

    How to handle Javascript Alert/pop up window in selenium webdriver

  16. 16

    How to handle Firefox Upload File window with Selenium WebDriver - Java

  17. 17

    How to open a new tab using Selenium WebDriver?

  18. 18

    How to double click on an element using Selenium Webdriver

  19. 19

    How to perform load testing using Selenium WebDriver?

  20. 20

    How to wait for an element NOT to be clickable using Selenium Webdriver?

  21. 21

    How to implement PhantomJS with Selenium WebDriver using java

  22. 22

    How to launch Safari with Selenium WebDriver using Java

  23. 23

    How to avoid the hidden classes using selenium webdriver

  24. 24

    How to wait for an element NOT to be clickable using Selenium Webdriver?

  25. 25

    how to click the div in css using selenium webdriver

  26. 26

    How to perform load testing using Selenium WebDriver?

  27. 27

    How to launch Safari with Selenium WebDriver using Java

  28. 28

    How to check the checkboxes using the Selenium Java WebDriver?

  29. 29

    Using Selenium Webdriver how to retrive date text

HotTag

Archive