检查 Selenium 页面上的文本
Check if text on page Selenium
我在 FireFox 中使用 Selenium IDE。
我想编写一个 IF 语句来搜索页面上的所有 text(),如果它找到匹配的文本 echo "Found it",否则 echo "not found".
到目前为止我的进展情况:
*somehow search here hopefully Whosebug save the day*
store | FOUND IT | found
store | NOT FOUND | notfound
if | ${test}==true |
echo | ${found} |
else | |
echo | ${notfound} |
endIf | |
请 不要 给我 JavaScript 代码等...,我正在使用 FireFox 插件 IDE。
谢谢!
您可以使用这个脚本。
storeText | css=body | text
storeEval |javascript{storedVars['text'].indexOf("Find me",0) > 0} | find
if | ${find}==true |
echo | FOUND IT|
else | |
echo | TEXT NOT FOUND |
endIf | |
在示例中,我使用 text 变量将所有文本存储在页面正文中,然后我使用 javascript 代码定位 在变量中找到我 文本。这保证在 Selenium IDE 中工作。如果您还有其他问题,请告诉我。
Rodel 的回答是正确的。但是有一种方法可以一步到位。
echo | javascript{if (document.documentElement.innerHTML.indexOf('Text_to_find') > 0) {'Found'} else {'Not Found'}}
我在 FireFox 中使用 Selenium IDE。
我想编写一个 IF 语句来搜索页面上的所有 text(),如果它找到匹配的文本 echo "Found it",否则 echo "not found".
到目前为止我的进展情况:
*somehow search here hopefully Whosebug save the day*
store | FOUND IT | found
store | NOT FOUND | notfound
if | ${test}==true |
echo | ${found} |
else | |
echo | ${notfound} |
endIf | |
请 不要 给我 JavaScript 代码等...,我正在使用 FireFox 插件 IDE。
谢谢!
您可以使用这个脚本。
storeText | css=body | text
storeEval |javascript{storedVars['text'].indexOf("Find me",0) > 0} | find
if | ${find}==true |
echo | FOUND IT|
else | |
echo | TEXT NOT FOUND |
endIf | |
在示例中,我使用 text 变量将所有文本存储在页面正文中,然后我使用 javascript 代码定位 在变量中找到我 文本。这保证在 Selenium IDE 中工作。如果您还有其他问题,请告诉我。
Rodel 的回答是正确的。但是有一种方法可以一步到位。
echo | javascript{if (document.documentElement.innerHTML.indexOf('Text_to_find') > 0) {'Found'} else {'Not Found'}}