After tracing down the errors I found out the code that causes the error:
find(:css, "#travel_control").click
find(:xpath, ".//*[@id='field_container']/a[#TRAVEL_MODE_INDEX[travel_mode]}]").click
It seems that Web driver could not find the #travel_control element and therefore it throws the ObsoleteElement Error. The #travel_control element in my test is actually an ajax call on a popup box so probably WebDriver still has some issue in handling elements with ajax request and javascript.
Nevertheless, I found some help from google groups regarding this issue. There does not seem to be a solution in that thread but there is one comment regarding a temporary fix for this issue which is to ignore the error and execute the same code again.
So I tried it and changed my code into:
begin
find(:css, "#travel_control").click
find(:xpath, ".//*[@id='field_container']/
a[#{TRAVEL_MODE_INDEX[travel_mode]}]").click
rescue Selenium::WebDriver::Error::ObsoleteElementError
find(:css, "#travel_control").click
find(:xpath, ".//*[@id='field_container']/
a[#{TRAVEL_MODE_INDEX[travel_mode]}]").click
end
However, This does not work for me and instead I get this error
Element is not currently visible and so may not be clicked (Selenium::WebDriver::Error::ElementNotDisplayedError)
It turns out because when I get the ObsoleteElementError, WebDriver actually is able to click the "#travel_control element. so what I need to change is to not click the same element again. Here is how I fix my test:
begin
find(:css, "#travel_control").click
find(:xpath, ".//*[@id='field_container']/a[#{TRAVEL_MODE_INDEX[travel_mode]}]").click
rescue Selenium::WebDriver::Error::ObsoleteElementError
#just execute the next element
find(:xpath, ".//*[@id='field_container']/a[#{TRAVEL_MODE_INDEX[travel_mode]}]").click
end
I face the same issue with JRuby 1.7.2, I would like to try your solution ...
ReplyDeleteCan you explain me this code?
find(:xpath, ".//*[@id='field_container']/a[#{TRAVEL_MODE_INDEX[travel_mode]}]").click
Hi Arun,
DeleteThe code is just to click an element with a particular ID.
The solution above is basically to try clicking the element again if we encountered the (Selenium::WebDriver::Error::ObsoleteElementError) error