Can selenium handle autocomplete?

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

    This may not work for everyone, but I simply added in a method that allowed me to type in characters with a delay.

    Actions builder = new Actions(this.webDriver);
        WebElement element = this.getWebElement();
        for (char c : value.toCharArray()) {
            builder = builder.sendKeys(element, c + "");
            builder.pause(100);
        }
    
        builder.build().perform();
    

    I then found the item that I wanted to click (

    resultsElement.findElement(By.xpath("//li[.='" + valueLabel + "']"))
    

    Where container is the resultsElement is the WebElement that contains the result set and value label is the value I want to click.

    Again, it may not work for all, but it worked for me and I thought it prudent to share.

提交回复
热议问题