![](/img/trans.png)
[英]How do I find an element that contains specific text in Selenium Webdriver (Java)?
[英]Selenium: how to find element with with specific text without contains option
請看這個:
<option data-="OK" value="110">
My Text
</option>
<option data-="OK" value="111">
My Text 2
</option>
我想找到特定的元素,所以我嘗試了這個:
option[contains(text(),'My Text')]
所以在這種情況下,我想找到2個WebElements
而我也想嘗試一下:
option[text()='My Text']
但是在這種情況下什么也沒找到。
有什么建議么 ?
編輯:
<optgroup label="some text">
</optgroup>
試試這個:
option[normalize-space(text())='My Text']
這是您要從中選擇值的下拉菜單嗎?
對於下拉菜單,您可以嘗試,
WebElement element=driver.findElement(By.xpath(".//*[@YOUR-XPATH-HERE"));
Select se=new Select(element);
se.selectByIndex(0);
要么
se.selectByVisibleText("My Text");
要么
se.selectByValue("110");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.