Validating web page text with special character

Hi,

I am new to ruby. I am using watir classic with ruby 1.9.3.

I want to validate some displayed web page text containing special
chars.
ex:

require ‘watir’
I then display the web page.

if browser.text.include? ("Michael’s group with other participants’.)
puts “verified”
else
puts “not verified”
end

the script runs into errors when it see’s the apostrophe. How do you
ignore or validate the apostrophe?

Michael

Dear Michael,

At your code …

if browser.text.include? ("Michael’s group with other participants’.)

The quotings are not matching!

if browser.text.include? “Michael’s group with other participants”

Abinoam Jr.

Abinoam Jr. wrote in post #1136606:

Dear Michael,

At your code …

if browser.text.include? ("Michael’s group with other participants’.)

The quotings are not matching!

if browser.text.include? “Michael’s group with other participants”

Abinoam Jr.

I forgot to type in quote. It should read as follows:

if browser.text.include? (“Michael’s group with other participants’.”)
puts “verified”
else
puts “not verified”
end

When it see’s the first apostrophe it fails.

On Thu, Feb 13, 2014 at 2:37 PM, Michael Z. [email protected]
wrote:

if browser.text.include? (“Michael’s group with other participants’.”)

When it see’s the first apostrophe it fails.

1.9.3 (main):0 > “some string”.include?(“Michael’s group with other
participants’.”)
=> false
1.9.3 (main):0 >

Seems fine to me. Perhaps you could provide a reproducible test
case, as well as your definition of what “fails” means?

On Tue, Feb 18, 2014 at 8:52 AM, Michael Z. [email protected]
wrote:

splash.rb:18: invalid multibyte char (US-ASCII)

Your example still doesn’t throw that exception for me, but since I
don’t have an info about your environment I’ll just suggest that you
try this with your values:

browser.goto(“http://example.com/”)
string = “Michael’s”
puts “#{browser.text.encoding} #{string.encoding}”

You can specify encoding for your whole file, e.g. add the line

encoding: UTF-8

to the head of your file, or as needed for specific strings, e.g.
string.force_encoding(“UTF-8”)

HTH,

Hassan S. wrote in post #1136612:

On Thu, Feb 13, 2014 at 2:37 PM, Michael Z. [email protected]
wrote:

if browser.text.include? (“Michael’s group with other participants’.”)

When it see’s the first apostrophe it fails.

1.9.3 (main):0 > “some string”.include?(“Michael’s group with other
participants’.”)
=> false
1.9.3 (main):0 >

Seems fine to me. Perhaps you could provide a reproducible test
case, as well as your definition of what “fails” means?

This is the script with error message:
require ‘watir’

browser = Watir::Browser.new
browser.maximize

begin
browser.goto - I display my web page
if browser.text.include? (“Michael’s”)
puts “pass”
else
puts “fail”
end
end
Error:
splash.rb:18: invalid multibyte char (US-ASCII)
splash.rb:18: syntax error, unexpected $end, expecting ‘)’
…f browser.text.include? ("Michael^a?Ts …

Hassan S. wrote in post #1137079:

On Tue, Feb 18, 2014 at 8:52 AM, Michael Z. [email protected]
wrote:

splash.rb:18: invalid multibyte char (US-ASCII)

Your example still doesn’t throw that exception for me, but since I
don’t have an info about your environment I’ll just suggest that you
try this with your values:

browser.goto(“http://example.com/”)
string = “Michael’s”
puts “#{browser.text.encoding} #{string.encoding}”

You can specify encoding for your whole file, e.g. add the line

encoding: UTF-8

to the head of your file, or as needed for specific strings, e.g.
string.force_encoding(“UTF-8”)

HTH,

I am using the IE-8 browser for my environment.

When I perform the test using the irb function, I do not get an error,
because the aspostrophie is automatically remove during entry. But, The
if/else test provides a nil (false)which makes the test fail.

I tried your idea’s , but received an error. I entered as follows:
#1
require ‘watir’
browser = Watir::Browser.new
browser.maximize
browser.goto(“http://example.com/”)- replace with my site
string = “Michael’s”

puts “#{browser.text.encoding} #{string.encoding}”

if browser.text.include? (“Michael’s”)
puts “pass”
else
puts “fails”
end
Result: Received a syntax error

#2
require ‘watir’
string.force_encoding(“UTF-8”)
browser = Watir::Browser.new
browser.maximize
browser.goto(“http://example.com/”)- replace with my site
if browser.text.include? (“Michael’s”)
puts “pass”
else
puts “fails”
end
Result: Received a syntax error
Thanks for your help, but I’m not sure what I am doing wrong.

On Tue, Feb 18, 2014 at 11:43 AM, Michael Z.
[email protected] wrote:

I am using the IE-8 browser for my environment.

By “environment” I meant what OS, what version/patch level of Ruby,
versions of gems, etc.

When I perform the test using the irb function, I do not get an error,
because the aspostrophie is automatically remove during entry.

That makes no sense to me.

if/else test provides a nil (false)which makes the test fail.

I’m also not sure what that means.

I tried your idea’s , but received an error. I entered as follows:
#1
require ‘watir’
browser = Watir::Browser.new
browser.maximize
browser.goto(“http://example.com/”)- replace with my site
string = “Michael’s”

puts “#{browser.text.encoding} #{string.encoding}”

I hope you didn’t really have a ‘>’ character at the start of the
line of that puts

if browser.text.include? (“Michael’s”)
puts “pass”
else
puts “fails”
end
Result: Received a syntax error

You will be much more likely to get useful help if you paste in the
ACTUAL ERROR MESSAGE with any accompanying stack trace
rather than meaningless noise like “received a syntax error”.

#2
require ‘watir’
string.force_encoding(“UTF-8”)

Of course that won’t work – “string” is undefined there. In my prior
example it is a variable with the value “Michael’s”.