[英]Selenium: how to find element with with specific text without contains option
Please see this: 请看这个:
<option data-="OK" value="110">
My Text
</option>
<option data-="OK" value="111">
My Text 2
</option>
I want to find specific element, so i have try this: 我想找到特定的元素,所以我尝试了这个:
option[contains(text(),'My Text')]
So i this case i found 2 WebElements
while i want to find the one that i want, i also try this: 所以在这种情况下,我想找到2个WebElements
而我也想尝试一下:
option[text()='My Text']
But in this case nothing found. 但是在这种情况下什么也没找到。
Any suggestions ? 有什么建议么 ?
Edit: 编辑:
<optgroup label="some text">
</optgroup>
试试这个:
option[normalize-space(text())='My Text']
Is this a dropdown you are trying to select value from? 这是您要从中选择值的下拉菜单吗?
for drop-downs you can try, 对于下拉菜单,您可以尝试,
WebElement element=driver.findElement(By.xpath(".//*[@YOUR-XPATH-HERE"));
Select se=new Select(element);
se.selectByIndex(0);
or 要么
se.selectByVisibleText("My Text");
or 要么
se.selectByValue("110");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.