The problem I am having is that I can’t seem to find how to get the Bowser.text.include? to look for the value of textinclude that I give it earlier in the program.
It seems to search literally for #{textinclude}, which is obviously not present.
This is my current code:
print( 'Enter your website: ' )
website = gets()
puts( "Testing #{website}" )
print( 'What text do you want to find? ' )
textinclude = gets()
puts( "Finding #{textinclude}" )
require 'watir'
browser = Watir::IE.new
browser.goto (website)
if browser.text.include? " #{textinclude} "
print("#{textinclude} present")
else
print("text not present")
end
Appreciate your help.
Thanks
Is that your exact code as pasted from your program?
Check the spaces around
if browser.text.include? " #{textinclude} "and make sure those aren’t interfering. E.g. if the sentence you’re looking for actually ends with afullstoprather than aspaceit could cause theinclude?to return false in my experience.You will require the .chomp like Tapio Saarinen said, otherwise you will get
\nat the end of yourtextinclude variable, removing this is the first step to being able to find your text.So I would try this
If that still fails, think about where the text is on the page. If it’s in a button’s value, or somewhere that is otherwise not actually
texton the page, then thetext.include?will not find it at all.P.s. I renamed your variable so I could read it properly 🙂