Can selenium handle autocomplete?

前端 未结 17 1292
粉色の甜心
粉色の甜心 2020-12-09 04:26

I have a test case that requires typing in a partial value into an ajax based textfield and verifying the list has the expected content. If it does, select the content. An

17条回答
  •  再見小時候
    2020-12-09 05:16

    A little variation using Prashanth's answer:

        /**
     * Selects the element at position idx from the autocomplete combo, considering the partialKeyword
     * @param driver
     * @param element
     * @param partialKeyword
     * @param idx
     * @throws InterruptedException
     */
    public static void selectAutoCompleteValue(WebDriver driver, WebElement element, String partialKeyword, Integer idx) throws InterruptedException{
        element.sendKeys(partialKeyword);
        Thread.sleep(1000);
        List  listItems = driver.findElements(By.cssSelector(".ui-autocomplete-item.ui-autocomplete-list-item"));
        listItems.get(idx).click();
    }
    

    Hope this helps!

提交回复
热议问题