Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you check the page for text using Selenium 2 and Firefox?

I am trying to check to see if text is present using Selenium 2 and Firefox but cant seem to find the method to use. I tried to use the method is_text_present which seems to be what everyone says work but will not work for me. I get the returned error:

NoMethodError: undefined method `is_text_present' for# Selenium::WebDriver::Driver:0x1017232e0 browser=:firefox

How do you check the page for text using Selenium 2 and Firefox?

When I tried this stack overflow option "Finding text in page with selenium 2" it did not work for me, I believe it doesn't work because I am using Ruby to do my test, not Java.

like image 788
Curtis Miller Avatar asked Dec 09 '22 05:12

Curtis Miller


2 Answers

If you don't know in which element should be your text, you can use :

driver.page_source.include? 'TEXT_TO_SEARCH'

Otherwise you can use as Llelong and Thomp suggested :

driver.find_element(:id=>"ELEMENT_ID").text.include? 'TEXT_TO_SEARCH'
driver.find_element(:class=>"ELEMENT_CLASS").text.include? 'TEXT_TO_SEARCH'
like image 73
gvo Avatar answered May 24 '23 23:05

gvo


You can find the text in JAVA using the following code snippet... Try using the same for Ruby:- driver.getPageSource().contains("TEXTTOSEARCH");

like image 27
Amit Horakeri Avatar answered May 24 '23 22:05

Amit Horakeri