简体   繁体   中英

Is it possible to select an element (drop-down value) using which contains?

Is it possible to select an element (drop-down value) using which contains?

My drop-down value is of 25 characters, as of now i'm using

myelement.SelectByText(mytext); // Here i'm passing full text of the drop-down value.

Wondering is it possible to select by passing partial value of the text?

Please let me know. ( Possible C# answers would be helpful )

Please try below code it should work

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM