简体   繁体   English

Sikuli Java查找包含特定文本的选择选项

[英]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.

相关问题 硒:如何查找带有特定文本的元素而没有包含选项 - Selenium: how to find element with with specific text without contains option 如何使用Sikuli + Java根据与其相邻的文本选择单选按钮? - How to select a radio button based on the text adjacent to it using Sikuli + Java? 如何使用Sikuli API从右键单击中选择选项 - How to select option from Right Click using Sikuli API 如何在Selenium Webdriver(Java)中找到包含特定文本的元素? - How do I find an element that contains specific text in Selenium Webdriver (Java)? 使用java时,在Sikuli中关闭文本识别(OCR) - text recognition (OCR) is switched off in Sikuli when using java 如何使用Sikuli Java Standalone jar输入文本? - How to type text using Sikuli Java Standalone jar? 使用java查找包含mongodb中特定值的数组的文档 - Find documents with array that contains a specific value in mongodb using java Selenium + Java = FindElements (list) 并检查其中一些是否包含特定文本 - Selenium + Java = FindElements (list) and check if some of them contains a specific text 如果文件中包含Java中的特定数据,则需要从文件中删除一行文本 - need to delete a line of text from a file if it contains specific data in Java 从 java 中的文本文件打印包含特定模式的行 - print a line that contains a specific pattern from a text-file in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM