使用Selenium IDE,如何测试元素的内部文本是否包含特定的字符串?例如:Selenium:测试元素是否包含一些文本
<p id="fred">abcde</p>
'id=fred' contains "bcd" = true)
使用Selenium IDE,如何测试元素的内部文本是否包含特定的字符串?例如:Selenium:测试元素是否包含一些文本
<p id="fred">abcde</p>
'id=fred' contains "bcd" = true)
的Selenium-IDE documentation是在这种情况下有所帮助。
您正在查找的命令是assertText
,定位器将是id=fred
,文本例如*bcd*
。
您能够使用jQuery,如果因此要尽量喜欢的东西
$("p#fred:contains('bcd')").css("text-decoration", "underline");
怎么会变成这样有可能与硒IDE? – 2012-03-29 09:00:00
有一个阅读这应该帮助。 http://www.vcskicks.com/selenium-jquery.php – 2012-03-29 09:05:45
似乎正则表达式可能的工作:
"The simplest character set is a character. The regular expression "the" contains three
character sets: "t," "h" and "e". It will match any line with the string "the" inside it.
This would also match the word "other". "
(从网站:http://www.grymoire.com/Unix/Regular.html)
如果您正在使用visual studio,则可以使用regula评估字符串r表达式(不仅仅包含):
using System.Text.RegularExpressions;
Regex.IsMatch("YourInnerText", @"^[a-zA-Z]+$");
我发布的表达式将检查该字符串是否仅包含字母。
然后,您的正则表达式将根据我的链接是“bcd”或您在运行时构建的某个字符串。或者:
Regex.IsMatch("YourInnerText", @"bcd");
(像反正东西)
希望它帮助。
您可以使用命令assertTextPresent
或verifyText
是的,但我试图得到一个部分匹配,而不是满的。此外,这不仅仅是可以使用的命令。 – 2012-03-29 09:35:50
哦。就在同一时刻。 – 2012-03-29 09:35:54
是的。不到一分钟太慢了。嘿嘿 – 2012-03-29 10:30:25
您还可以使用:
assertElementPresent
css=p#fred:contains('bcd')
谢谢,这就是我所需要的:'css = p:contains('foo')'。不过,我被告知它已被弃用。 – LarsH 2012-09-13 20:49:55
即使我稍微明白了你的意思,我会给你答案的。 – 2012-03-29 12:01:34
@Slanec是否有任何东西,我可以搜索文本并点击它? – 2015-05-08 09:59:11
文档的关键点在[匹配文本模式](http://docs.seleniumhq.org/docs/02_selenium_ide.jsp#matching-text-patterns)中进一步讨论了通配符。 – icc97 2016-03-07 09:05:06