Test autocomplete with Selenium webdriver

后端 未结 3 1564
感动是毒
感动是毒 2020-12-06 07:09

I have a text box in which when I type one letter say \'s\' , it displays a list of results ( like google search) .

I am using latest selenium webdriver with java. <

相关标签:
3条回答
  • 2020-12-06 07:38

    I found a workaround about this. My problem was:

    1. Selenium inputted 'Mandaluyong' to an auto-suggest location field
    2. The auto-suggest field appears together with the matched option
    3. Then selenium left the auto-suggest drop-down open not selecting the matched option.

    What I did was:

            driver.findElement(By.name("fromLocation")).sendKeys("Mandaluyong");
            driver.findElement(By.name("fromLocation")).sendKeys(Keys.TAB);
    

    This is because on a manual test, when I try to press TAB key, two things were done by the system:

    1. Picks the matched option from the auto-suggest drop-down
    2. Closes the auto-suggest drop-down
    0 讨论(0)
  • 2020-12-06 07:44

    I believe you are testing auto-suggest here (not auto-complete)

    Steps I follow -

    1. Enter something in the input field
    2. Click on the suggestion you want to choose. (You can find the xpath using some tools like Firebug with Firepath, Chrome, etc.)
    3. Verify the text in the input field is same as expected.
    0 讨论(0)
  • 2020-12-06 07:44

    This should be a temporary workaround for now.

    WebDriver driver = new FirefoxDriver();
        driver.get("http://www.kayak.com/");
        DefaultSelenium sel = new WebDriverBackedSelenium(driver,"http://www.kayak.com/");
    
        sel.type("//input[@id='destination']", "s");
        sel.fireEvent("//input[@id='destination']", "keydown");
    
    0 讨论(0)
提交回复
热议问题