Discussion:
[wtr-general] Watir [DEPRECATION] ["stale_present"] Checking `#present? == false`
r***@gmail.com
2018-09-05 07:01:15 UTC
Permalink
Hi Titus,

I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"] Checking
`#present? == false` to determine a stale element is deprecated. Use
`#stale? == true` instead.

If I use

@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element

0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
staleness of unused element" unless @element?[0m
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in `waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in <top
(required)>'?[0m

Why can't I use `@b.span(class: "spinner").wait_while(&:present?)` ? Hi, I
am designing a common framework for all of my project in my company using
WATIR. So this kind of code in my Framework level is pretty important. Can
you please let me know why it is deprecated?
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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
2018-09-05 14:36:16 UTC
Permalink
It has to do with how Watir caches elements and being consistent in how it
responds.

"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"

If you are asking the former, you're fine. If you are asking the latter,
you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.



On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"] Checking
`#present? == false` to determine a stale element is deprecated. Use
`#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
I am designing a common framework for all of my project in my company using
WATIR. So this kind of code in my Framework level is pretty important. Can
you please let me know why it is deprecated?
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.
rajagopalan madasami
2018-09-05 15:41:08 UTC
Permalink
Hi, I am creating log in y framework and this error message is troubling me
. There is a spinner comes and I need to wait until that spinner disappear
and my first line of code perfectly does the Job, why do want to deprecate
that method? I feel like you stared to deprecate all the necessary methods
in WATIR, like link locator is another one. I don't know why are doing
this.
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in how it
responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the latter,
you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"] Checking
`#present? == false` to determine a stale element is deprecated. Use
`#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
I am designing a common framework for all of my project in my company using
WATIR. So this kind of code in my Framework level is pretty important. Can
you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 an
For more options, visit https://groups.google.com/d/optout.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.
rajagopalan madasami
2018-09-05 16:06:00 UTC
Permalink
Okay can you please let me know how can i replace the first line code of my
mine?

element=b.span()
element.wait_until(&:stale?)

Like this?





On Wed 5 Sep, 2018, 9:11 PM rajagopalan madasami, <
Post by rajagopalan madasami
Hi, I am creating log in y framework and this error message is troubling
me . There is a spinner comes and I need to wait until that spinner
disappear and my first line of code perfectly does the Job, why do want to
deprecate that method? I feel like you stared to deprecate all the
necessary methods in WATIR, like link locator is another one. I don't know
why are doing this.
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in how
it responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the latter,
you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"] Checking
`#present? == false` to determine a stale element is deprecated. Use
`#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
Hi, I am designing a common framework for all of my project in my company
using WATIR. So this kind of code in my Framework level is pretty
important. Can you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 an
For more options, visit https://groups.google.com/d/optout.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.
rajagopalan madasami
2018-09-05 16:30:56 UTC
Permalink
Yes I am asking the former, I need to wait until spinner goes away. So
former one is necessary for me. Buy why do you plan to deprecate such a
good method which is very much necessary?
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in how it
responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the latter,
you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"] Checking
`#present? == false` to determine a stale element is deprecated. Use
`#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
I am designing a common framework for all of my project in my company using
WATIR. So this kind of code in my Framework level is pretty important. Can
you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 an
For more options, visit https://groups.google.com/d/optout.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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
2018-09-06 01:44:12 UTC
Permalink
This is another example of the deprecation notice being thrown more often
than it should be. I've verified that your code will work after my planned
deprecation. I can't figure out how to restrict this deprecation notice, so
I'll add something to the message.

Right now, to avoid that notice, you can do: element.wait_while(&:exists?)

Watir and Selenium have fundamentally different ideas of what an element
"is." A Selenium Element is defined by the object reference returned by the
driver. If that reference is no longer valid, the element no longer exists.
A Watir Element is whatever exists is at the provided locator, period. The
Watir approach is more useful if you are focused on testing functionality
vs implementation. When watir-webdriver was created, a lot of Selenium
implementation ideas creeped into Watir. This refactoring is make the
distinction more consistent with the original intentions of Watir.

If a Watir user cares about the Selenium notion of what an element is,
we've provided the `#stale?` method to allow you to figure out if the
driver object has gone away. Additionally, for performance reasons Watir
caches the Selenium element and tries to re-use it whenever possible. which
adds a bit of extra complexity.

If you're curious, the refactoring is going to change #exists? from this:

def exists?
return false if located? && stale?
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end


to this:

def exists?
if located? && stale?
reset!
elsif located?
return true
end

assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end


and `#present?` will look like:

def present?
begin
assert_exists
@element.displayed?
rescue Selenium::WebDriver::Error::StaleElementReferenceError
reset!
retry # (this was changed from just returning false)
rescue UnknownObjectException, UnknownFrameException
false
end
end





On Wednesday, September 5, 2018 at 9:31:12 AM UTC-7, rajagopalan madasami
Post by rajagopalan madasami
Yes I am asking the former, I need to wait until spinner goes away. So
former one is necessary for me. Buy why do you plan to deprecate such a
good method which is very much necessary?
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in how
it responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the latter,
you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"] Checking
`#present? == false` to determine a stale element is deprecated. Use
`#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
Hi, I am designing a common framework for all of my project in my company
using WATIR. So this kind of code in my Framework level is pretty
important. Can you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 an
For more options, visit https://groups.google.com/d/optout.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.
r***@gmail.com
2018-09-11 12:04:45 UTC
Permalink
Post by Titus Fortner
element.wait_while(&:exists?)
No, this wouldn't work, I have to wait until the element is visible,
element becomes invisible when loading completes.

And also, I am checking whether element is visible or not, I am checking
whether previously located element exist in the DOM. So this line
b.div().wait_until_present or b.div.wait_until(&:present) perfectly needed
for my program.

I am well aware of how element is located in selenium and WATIR. but I
don't understand the deprecation message has to be thrown such a meaningful
method. Please remove this message completely.

Thanks.
Post by Titus Fortner
This is another example of the deprecation notice being thrown more often
than it should be. I've verified that your code will work after my planned
deprecation. I can't figure out how to restrict this deprecation notice, so
I'll add something to the message.
Right now, to avoid that notice, you can do: element.wait_while(&:exists?)
Watir and Selenium have fundamentally different ideas of what an element
"is." A Selenium Element is defined by the object reference returned by the
driver. If that reference is no longer valid, the element no longer exists.
A Watir Element is whatever exists is at the provided locator, period. The
Watir approach is more useful if you are focused on testing functionality
vs implementation. When watir-webdriver was created, a lot of Selenium
implementation ideas creeped into Watir. This refactoring is make the
distinction more consistent with the original intentions of Watir.
If a Watir user cares about the Selenium notion of what an element is,
we've provided the `#stale?` method to allow you to figure out if the
driver object has gone away. Additionally, for performance reasons Watir
caches the Selenium element and tries to re-use it whenever possible. which
adds a bit of extra complexity.
def exists?
return false if located? && stale?
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end
def exists?
if located? && stale?
reset!
elsif located?
return true
end
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end
def present?
begin
assert_exists
@element.displayed?
rescue Selenium::WebDriver::Error::StaleElementReferenceError
reset!
retry # (this was changed from just returning false)
rescue UnknownObjectException, UnknownFrameException
false
end
end
On Wednesday, September 5, 2018 at 9:31:12 AM UTC-7, rajagopalan madasami
Post by rajagopalan madasami
Yes I am asking the former, I need to wait until spinner goes away. So
former one is necessary for me. Buy why do you plan to deprecate such a
good method which is very much necessary?
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in how
it responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the latter,
you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"]
Checking `#present? == false` to determine a stale element is deprecated.
Use `#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
Hi, I am designing a common framework for all of my project in my company
using WATIR. So this kind of code in my Framework level is pretty
important. Can you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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
2018-09-11 15:54:49 UTC
Permalink
The deprecation message is thrown when rescuing a stale exception during a
call for #exists? / #visible? #present? because when we make the code
changes below, tests that rely on this behavior will fail. They need to
know about it, so there needs to be a message. Yes, the message is
happening even in use cases that won't change, so I'll need to adjust the
message.

As for the specific code I suggested, you wouldn't be getting a stale
element warning if the element was in the DOM and merely not displayed. As
such `wait_while(&:exists?)` would do what you need it to do just fine.
Alternately, the method `#wait_while_present` should work as well since it
is constantly locating from scratch. Yes, this is just for the element
going away. To deal with the element showing up and then going away is a
completely separate concern.

Also, for note, specific requests for changing code are better done as
github issues so I can keep track of them.
Post by Titus Fortner
element.wait_while(&:exists?)
No, this wouldn't work, I have to wait until the element is visible,
element becomes invisible when loading completes.
And also, I am checking whether element is visible or not, I am checking
whether previously located element exist in the DOM. So this line
b.div().wait_until_present or b.div.wait_until(&:present) perfectly needed
for my program.
I am well aware of how element is located in selenium and WATIR. but I
don't understand the deprecation message has to be thrown such a meaningful
method. Please remove this message completely.
Thanks.
Post by Titus Fortner
This is another example of the deprecation notice being thrown more often
than it should be. I've verified that your code will work after my planned
deprecation. I can't figure out how to restrict this deprecation notice, so
I'll add something to the message.
Right now, to avoid that notice, you can do: element.wait_while(&:exists?
)
Watir and Selenium have fundamentally different ideas of what an element
"is." A Selenium Element is defined by the object reference returned by the
driver. If that reference is no longer valid, the element no longer exists.
A Watir Element is whatever exists is at the provided locator, period. The
Watir approach is more useful if you are focused on testing functionality
vs implementation. When watir-webdriver was created, a lot of Selenium
implementation ideas creeped into Watir. This refactoring is make the
distinction more consistent with the original intentions of Watir.
If a Watir user cares about the Selenium notion of what an element is,
we've provided the `#stale?` method to allow you to figure out if the
driver object has gone away. Additionally, for performance reasons Watir
caches the Selenium element and tries to re-use it whenever possible. which
adds a bit of extra complexity.
def exists?
return false if located? && stale?
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end
def exists?
if located? && stale?
reset!
elsif located?
return true
end
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end
def present?
begin
assert_exists
@element.displayed?
rescue Selenium::WebDriver::Error::StaleElementReferenceError
reset!
retry # (this was changed from just returning false)
rescue UnknownObjectException, UnknownFrameException
false
end
end
On Wednesday, September 5, 2018 at 9:31:12 AM UTC-7, rajagopalan madasami
Post by rajagopalan madasami
Yes I am asking the former, I need to wait until spinner goes away. So
former one is necessary for me. Buy why do you plan to deprecate such a
good method which is very much necessary?
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in how
it responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the
latter, you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"]
Checking `#present? == false` to determine a stale element is deprecated.
Use `#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not check
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels) in
<top (required)>'?[0m
Hi, I am designing a common framework for all of my project in my company
using WATIR. So this kind of code in my Framework level is pretty
important. Can you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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
2018-09-12 01:06:17 UTC
Permalink
Good news. I figured out how to minimize this message. Everything should be
better in 6.14. :)
Post by Titus Fortner
The deprecation message is thrown when rescuing a stale exception during a
call for #exists? / #visible? #present? because when we make the code
changes below, tests that rely on this behavior will fail. They need to
know about it, so there needs to be a message. Yes, the message is
happening even in use cases that won't change, so I'll need to adjust the
message.
As for the specific code I suggested, you wouldn't be getting a stale
element warning if the element was in the DOM and merely not displayed. As
such `wait_while(&:exists?)` would do what you need it to do just fine.
Alternately, the method `#wait_while_present` should work as well since it
is constantly locating from scratch. Yes, this is just for the element
going away. To deal with the element showing up and then going away is a
completely separate concern.
Also, for note, specific requests for changing code are better done as
github issues so I can keep track of them.
Post by Titus Fortner
element.wait_while(&:exists?)
No, this wouldn't work, I have to wait until the element is visible,
element becomes invisible when loading completes.
And also, I am checking whether element is visible or not, I am checking
whether previously located element exist in the DOM. So this line
b.div().wait_until_present or b.div.wait_until(&:present) perfectly needed
for my program.
I am well aware of how element is located in selenium and WATIR. but I
don't understand the deprecation message has to be thrown such a meaningful
method. Please remove this message completely.
Thanks.
Post by Titus Fortner
This is another example of the deprecation notice being thrown more
often than it should be. I've verified that your code will work after my
planned deprecation. I can't figure out how to restrict this deprecation
notice, so I'll add something to the message.
Right now, to avoid that notice, you can do: element.wait_while(&
:exists?)
Watir and Selenium have fundamentally different ideas of what an element
"is." A Selenium Element is defined by the object reference returned by the
driver. If that reference is no longer valid, the element no longer exists.
A Watir Element is whatever exists is at the provided locator, period. The
Watir approach is more useful if you are focused on testing functionality
vs implementation. When watir-webdriver was created, a lot of Selenium
implementation ideas creeped into Watir. This refactoring is make the
distinction more consistent with the original intentions of Watir.
If a Watir user cares about the Selenium notion of what an element is,
we've provided the `#stale?` method to allow you to figure out if the
driver object has gone away. Additionally, for performance reasons Watir
caches the Selenium element and tries to re-use it whenever possible. which
adds a bit of extra complexity.
def exists?
return false if located? && stale?
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end
def exists?
if located? && stale?
reset!
elsif located?
return true
end
assert_exists
true
rescue UnknownObjectException, UnknownFrameException
false
end
def present?
begin
assert_exists
@element.displayed?
rescue Selenium::WebDriver::Error::StaleElementReferenceError
reset!
retry # (this was changed from just returning false)
rescue UnknownObjectException, UnknownFrameException
false
end
end
On Wednesday, September 5, 2018 at 9:31:12 AM UTC-7, rajagopalan
Post by rajagopalan madasami
Yes I am asking the former, I need to wait until spinner goes away. So
former one is necessary for me. Buy why do you plan to deprecate such a
good method which is very much necessary?
Post by Titus Fortner
It has to do with how Watir caches elements and being consistent in
how it responds.
"#present?" is asking "can a user see an element at this location?"
This is different from "did the element I previously located change?"
If you are asking the former, you're fine. If you are asking the
latter, you might need to change your code.
I can take another pass at making sure the warning is sufficiently narrow.
On Wednesday, September 5, 2018 at 12:01:15 AM UTC-7,
Post by r***@gmail.com
Hi Titus,
I am getting this warning while I execute this code
@b.span(class: "spinner").wait_while(&:present?)
2018-09-05 12:26:45 WARN Watir [DEPRECATION] ["stale_present"]
Checking `#present? == false` to determine a stale element is deprecated.
Use `#stale? == true` instead.
If I use
@b.span(class: "spinner").wait_until(&:stale?)
Watir::Exception::Error: Can not check staleness of unused element
0) scenario1-Contact Example
?[31mFailure/Error: raise Watir::Exception::Error, "Can not
?[31m?[0m
?[31mWatir::Exception::Error:?[0m
?[31m Can not check staleness of unused element?[0m
?[36m# ./Source/FrameWorkModules/Chrome.rb:168:in
`waitForPageLoad'?[0m
?[36m# ./Source/LoginModule/login.rb:72:in `driverSing'?[0m
?[36m# ./Source/FrameWorkModules/PullTheTestCases.rb:7:in
`initialize'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `new'?[0m
?[36m# ./Source/Contact_Create_spec.rb:36:in `block (4 levels)
in <top (required)>'?[0m
Hi, I am designing a common framework for all of my project in my company
using WATIR. So this kind of code in my Framework level is pretty
important. Can you please let me know why it is deprecated?
--
--
Before posting, please read
https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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 https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.
r***@gmail.com
2018-09-12 16:53:16 UTC
Permalink
Yes I saw that in your article, that's best idea. Thanks.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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.
r***@gmail.com
2018-09-12 16:52:45 UTC
Permalink
You are perfectly correct, yes wait_while(&:exists?) will do the same Job, I have not noticed when you explained me first time.thanks.
--
--
Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group.
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...