[英]Sikuli Java find a select option that contains specific text
I am trying to click on a specific option from a select statement using Sikuli in Java. 我试图在Java中使用Sikuli从select语句中单击特定选项。
Given this select statement: 鉴于以下选择语句:
<select name="mySelect">
<option value="ab">AB 273xc Some Text</option>
<option value="cd">CD i8df4 Some More Text</option>
<option value="ef">EF q43th And Text Once More</option>
</select>
The following works if I know the full exact text contained in the option: 如果我知道该选项中包含的完整文本,则可以进行以下操作:
driver.findElement(By.xpath("//select[@name='mySelect']/option[.='CD i8df4 Some More Text']")).click();
The problem is that there is always random text within the string (i8df4 in this case) which changes every time, so I will not know what this text will be. 问题在于,字符串中始终存在随机文本(在这种情况下为i8df4),该文本每次都会更改,因此我不知道该文本是什么。
So I want to click on the option that contains the text "Some More Text" at the end. 因此,我想单击最后包含文本“ Some More Text”的选项。 I see there is a CONTAINS function but I cannot figure out how to use it in this case (if its even possible to use).
我看到有一个CONTAINS函数,但是在这种情况下(即使可以使用),我不知道该如何使用。
So need to do some kind of pattern match or regex in the option part like this: 因此需要在选项部分中进行某种模式匹配或正则表达式,例如:
option[.='do pattern match here looking for Some More Text']
To test the value of a part of text you can use contains()
. 要测试一部分文本的值,可以使用
contains()
。 Therefore you may try this: 因此,您可以尝试以下操作:
"//select[@name='mySelect']/option[contains(.,'Some Text')]"
But in my view it would be better to use the value attribute: 但我认为最好使用value属性:
"//select[@name='mySelect']/option[@value='ab']"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.