使用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