2016-07-01 37 views
0

我在FireFox中使用Selenium IDE。檢查頁面上的文字Selenium

我想編寫一個IF語句,它將搜索頁面上的所有文本(),如果它找到匹配的文本回聲「找到它」,否則回顯「未找到」。

在那裏我有這麼遠:

*somehow search here hopefully Stackoverflow save the day* 

store | FOUND IT | found 
store | NOT FOUND | notfound 

if | ${test}==true | 
echo | ${found} | 

else | | 
echo | ${notfound} | 

endIf | | 

請不要給我的JavaScript代碼等等,我使用Firefox的插件IDE。

謝謝!

+0

這是http://stackoverflow.com/questions/14974508/webdriverhow-to-find-if-text-exists-on-page –

+0

@JosephEvans的可能重複這並不使用'硒IDE' – RemcoW

+1

讓我們開始說,我不知道如何編寫'Selnium IDE'的腳本。我知道在插件中有一個選項'assertBodyText(pattern)'。這將檢查傳入的'pattern'是否在頁面源代碼中,這似乎正是你想要的。 – RemcoW

回答

1

您可以使用此腳本。

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

在示例中,我存儲的所有文本在頁面主體使用文本變量然後我用JavaScript代碼來定位發現我的變量文本。這可以保證在Selenium IDE中工作。如果您還有其他問題,請告訴我。

0

通過回答Rodel是正確的。但是,只有一步就能做到這一點。

echo | javascript{if (document.documentElement.innerHTML.indexOf('Text_to_find') > 0) {'Found'} else {'Not Found'}}