Tuesday, August 9, 2016

How to handle autocomplete feature in Selenium Webdriver


jQuery UI Autocomplete - Default functionality

7 comments:

  1. HI Mukesh,
    I followed your video on Handling hidden element. That helped me in overcoming on hurdle. Now I have another challenge.
    Scenario is :
    I click on Hidden button on first screen, which result in opening of a window but part of main screen.
    All the elements on that window are hidden.
    I am not able to find a solution on how to put wait after I click on button on first screen so that it should wait for elements on 2nd window to appear.
    As of now, I am not able to think anything apart from thread.sleep
    Kindly help.

    ReplyDelete
    Replies
    1. Just my own opinion, you can continue with the thread.sleep(), or use explicit wait. then switch to the new window.

      Delete
  2. Hi Mukesh,
    I have tried your bootstrap dropdown using TestNG framework. I got Null Pointer Exception. Could you please help me to resolve this. Here is my code.
    public class BootStrapDropDown {
    public static WebDriver driver;

    @Test
    public void getDriver() {
    System.setProperty("webdriver.gecko.driver",
    "E://Nasreen Projects//geckodriver-v0.11.1-win32//geckodriver.exe");
    driver = new FirefoxDriver();
    driver.get("http://seleniumpractise.blogspot.in/2016/08/bootstrap-dropdown-example-for-selenium.html");
    driver.manage().window().maximize();
    System.out.println("Navigated");
    }

    @Test
    public void bootStrapDropDown() throws InterruptedException{
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.xpath(".//*[@id='menu1']")).click();
    Thread.sleep(5000);
    List elementList=driver.findElements(By.xpath("//ul[@class='dropdown-menu']//li/a"));
    for (WebElement element : elementList)

    {
    String innerHtml=element.getAttribute("innerHTML");
    System.out.println("Values " +innerHtml);
    if(innerHtml.contentEquals("JavaScript"))
    {
    element.click();
    break;
    }

    }

    }

    ReplyDelete
    Replies
    1. You are missing the "WebDriver" interface when you are instantiating your browser. also, you might need to make it public and static.

      Delete
  3. thanks for this article it is very informative.Selenium Training in Chennai

    ReplyDelete