Rupesh Shinde
Rupesh Shinde

Reputation: 1956

Can we use two strings in 'selectByVisibleText' method in Seleniumwebdriver

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?

Upvotes: 1

Views: 419

Answers (1)

Vivek Singh
Vivek Singh

Reputation: 3649

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.

Upvotes: 3

Related Questions