Can we use two strings in 'selectByVisibleText

2019-09-03 22:22发布

问题:

I have a Situation where my String is getting merged with symbol '»' after running a script. So after detecting an element from Drop-down element i have to Select it only by visible Text but i have to add » before my String.

Is their any way to handle this?

回答1:

You can do one thing in such a case:

WebElement web = driver.findElement(By.xpath("//select"));
List<WebElement> lst2 = web.findElements(By
        .xpath(".//option[contains(text(),'<yourText>')]"));
    for (WebElement option : lst2) {
    if (!option.isSelected()) {
        option.click();
    }
}

Hope this would help, thanks.