Discussion:
[wtr-general] Selenium Code is working but WATIR code fails to produce the result
Raja gopalan
2017-08-02 06:14:39 UTC
Permalink
Titus,

I tried but it both reports the following error.

If I use ,

b.alert.ok

then I am having the following error

Uncaught exception: undefined method `alert' for
#<Watir::HTMLElement:0x2050068>
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/elements/element.rb:693:in
`method_missing'
C:/Users/rajagopalan.m/RubymineProjects/SeleniumLearning/Contact/ModuleExample.rb:140:in
`<top (required)>'

If I use

iframe.b.alert.ok

then I have the following error,

Uncaught exception: unable to locate alert
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:115:in `rescue
in wait_for_exists'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:106:in `
wait_for_exists'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:36:in
`ok'
C:/Users/rajagopalan.m/RubymineProjects/SeleniumLearning/Contact/
ModuleExample.rb:140:in `<top (required)>'
Yes, you need to use `browser.alert.ok` directly
If you really need to do it in the context of iframe, you can do
`iframe.browser.alert.ok` (so long as iframe has already been located)
Selenium won't let you send any wire call that isn't related to an alert
if an alert is displayed.
Okay, this actually resolves the problem, Yes as you say, it's inside the
frame and when I use as shown below
iframe1 = browser.iframe(id: 'iframe1')
iframe1.element(id: 'element_inside_frame').click
it works, But another problem arises in the case of alert, I don't know
how to handle alert now.
If I write
iframe1.alert.ok
It simply throws the error by saying 'alert' function is not found for
iframe1. Can you tell me how to handle the alert when alert appears inside
the frame?
Working with iframes is approached differently in selenium & Watir.
In Selenium you are responsible for explicitly switching into and out of
driver.switch_to.frame('iframe1')
driver.find_element(id: 'element_inside_frame').click
driver.switch_to.default_content
driver.find_element(id: 'element_outside_frame').click
browser.iframe(id: 'iframe1').element(id: 'element_inside_frame').click
browser.element(id: 'element_outside_frame').click
The tradeoff for this behavior is that you have to include the iframe
definition as part of every element signature inside the iframe.
iframe1 = browser.iframe(id: 'iframe1')
iframe1.element(id: 'element_inside_frame').click
iframe1.element(id: 'also_inside_frame').click
You could have elements with the same id in multiple different
frames/browsing contexts. Watir requires you to explicitly specify which
one you want.
But why this difficulty while I use in WATIR? Selenium is allowing me
to access without any these kind of trouble. WATIR should eases that the
selenium coding, but here it makes it difficult.
Watir should now only send the null value to the frame endpoint if the
element in question is inside an iframe. So this could make sense. You need
to include the iframe definition as a parent object whenever defining
elements inside of it.
--
--
Before posting, please read http://watir.com/support. In short: search
before you ask, be nice.
http://groups.google.com/group/watir-general
---
You received this message because you are subscribed to the Google
Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Titus Fortner
2017-08-02 14:54:41 UTC
Permalink
The first error indicates that b is an element, not a browser. The second error means there isn't an alert open.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Raja gopalan
2017-08-03 07:28:54 UTC
Permalink
No, clearly not!


I have written the below code

puts '-------------------------------------------------'
iframe=b.iframe(id: "mymodalerr")
puts b.class
b.alert.ok
puts '-------------------------------------------------'

Output
-------------------------------------------------
Watir::Browser
This code has slept for the duration of the default timeout waiting for an
Alert to exist. If the test is still passing, consider using Alert#exists?
instead of rescuing UnknownObjectException
Uncaught exception: unable to locate alert
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:115:in `rescue
in wait_for_exists'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:106:in `
wait_for_exists'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:36:in
`ok'
C:/Users/rajagopalan.m/RubymineProjects/SeleniumLearning/Contact/
ModuleExample.rb:142:in `<top (required)>'

Did you notice that b is Browser object?



And when I write the below


puts '-------------------------------------------------'
iframe=b.iframe(id: "mymodalerr")
puts iframe.b.class
iframe.b.alert.ok
puts '-------------------------------------------------'




Output

-------------------------------------------------
Watir::HTMLElement
Uncaught exception: undefined method `alert' for
#<Watir::HTMLElement:0x372de18>
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/elements/element.rb:693:in
`method_missing'
C:/Users/rajagopalan.m/RubymineProjects/SeleniumLearning/Contact/ModuleExample.rb:142:in
`<top (required)>'




So iframe.b is not returning Browser object, So this must be a bug? What do
you say?
Post by Titus Fortner
The first error indicates that b is an element, not a browser. The second
error means there isn't an alert open.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Raja gopalan
2017-08-04 12:14:59 UTC
Permalink
Ah, okay, sorry! I mistook that the declared variable has to be used.

My problem was resolved, infact it's not even a alert, it's a html page
comes within frame. Thanks for help.
Ah, `iframe.b` is not `iframe.browser`.
Post by Raja gopalan
No, clearly not!
I have written the below code
puts '-------------------------------------------------'
iframe=b.iframe(id: "mymodalerr")
puts b.class
b.alert.ok
puts '-------------------------------------------------'
Output
-------------------------------------------------
Watir::Browser
This code has slept for the duration of the default timeout waiting for
an Alert to exist. If the test is still passing, consider using Alert#exists?
instead of rescuing UnknownObjectException
Uncaught exception: unable to locate alert
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:115:in `rescue
in wait_for_exists'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:106:in
`wait_for_exists'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/alert.rb:36:in
`ok'
C:/Users/rajagopalan.m/RubymineProjects/SeleniumLearning/Contact/
ModuleExample.rb:142:in `<top (required)>'
Did you notice that b is Browser object?
And when I write the below
puts '-------------------------------------------------'
iframe=b.iframe(id: "mymodalerr")
puts iframe.b.class
iframe.b.alert.ok
puts '-------------------------------------------------'
Output
-------------------------------------------------
Watir::HTMLElement
Uncaught exception: undefined method `alert' for
#<Watir::HTMLElement:0x372de18>
C:/Ruby23/lib/ruby/gems/2.3.0/gems/watir-6.5.0/lib/watir/elements/element.rb:693:in
`method_missing'
C:/Users/rajagopalan.m/RubymineProjects/SeleniumLearning/Contact/ModuleExample.rb:142:in
`<top (required)>'
So iframe.b is not returning Browser object, So this must be a bug? What
do you say?
Post by Titus Fortner
The first error indicates that b is an element, not a browser. The
second error means there isn't an alert open.
--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

watir-***@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+***@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...