Can selenium handle autocomplete?

前端 未结 17 1325
粉色の甜心
粉色の甜心 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:23

    There are few answers with code here. So, I will do my contribution.

    The code that I'm using to select an item in the autocomplete component from PrimeFaces 2.2:

    driver.findElement(By.id(codigoBanco_input)).sendKeys("text");
    waitForElementLocated(By.cssSelector(listItensSelector), 5);
    List listItems = driver.findElements(By.cssSelector(listItensSelector));
    Actions builder = new Actions(driver);
    builder.moveToElement(listItems.get(0)).build().perform();
    WebDriverWait wait = new WebDriverWait(driver, 5); 
    
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(itemSelector)));
            driver.findElement(By.cssSelector(itemSelector)).click();
    

提交回复
热议问题