1

I am trying to automate an application with consist of nested iframes. My First approach was with watir-webdriver but it is taking way too long to fill each field and I've enter many. An example of an element in my page class is below:

in_iframe(:id => 'something') do |frame|
  in_iframe({:id => 'something'}, frame) do |frame|
   in_iframe({:id => 'something'}, frame) do |frame|
    in_iframe({:id => 'something'}, frame) do |frame|
     in_iframe({:id => 'something'}, frame) do |frame|
       text_field(:first_name, :id => 'something', :frame => frame)           
     end
    end
   end
  end
end

After trying out with watir-webdriver, I decided to go ahead with selenium-webdriver but i am getting StaleElementReferenceError repeatedly. I even kept a begin rescue retry block to avoid this but it keeps throwing the error.

All the elements are stored in page class and i am using populate_page_with method of page class to enter values.

my_step.rb

When /^I (?:select|fill in) "(.*)" for (.+) (?:text field|drop down)$/ do |value, page_element|
  wait = Selenium::WebDriver::Wait.new(:timeout => 30)
  wait.until { @current_page.send(page_element.gsub(" ","_").downcase + "_element").exists? }
  @current_page.enter_element_value(page_element, value)
end

my_page.rb

class MyPage
  include PageObject

  in_iframe(:id => 'something') do |frame|
    in_iframe({:id => 'something'},frame) do |frame|
      text_field(:my_element, :id => 'something', :frame => frame)
    end
  end
end

enter_element_value function

def enter_element_value(field, value)
  populate_page_with "#{field.downcase.gsub(' ','_')}".to_sym => value
end

I tried to enter the same drop down with selenium functions and i was able to

sleep 5
@browser.switch_to.frame('GFXLoanSelectorFrame')
@browser.find_element(:id => 'lsProcCombo').find_elements(:tag_name => 'option')[1].click
@browser.switch_to.default_content

And if I call my step to enter the same drop down again it throws the StaleElementReferenceError error. I am not sure what exactly is causing this. Also, Please let me know if I can follow any other approach to speed up the execution because with watir-webdriver it took around 10 minutes to fill only 2 screen which is like 20% of my target.

yudi2312
  • 323
  • 1
  • 4
  • 21

2 Answers2

0

default content I believe got back to the root page, you will need to navigate bath through to the parent frame from the beginning.

Consider a different recursive method.

Jay Byford-Rew
  • 5,736
  • 1
  • 35
  • 36
0

staleelementexception is mostly caused when you loose the reference of the object after a action is performed and the state is changed. it may be due to ajax call or dom update. you can find different approaches discussed here How to avoid "StaleElementReferenceException" in Selenium?

Community
  • 1
  • 1
skumar
  • 180
  • 3
  • 17
  • I tried the same approach with begin rescue retry block and it gives me the same error. The issue is coming with the page-object '_element' method. If i use page object method to click an element it works (eg. page.my_button) but if i try to get the element and then click on it, i get the above error (eg: page.my_button_element.click ). As i am guessing, page object is returning reference to the old element. – yudi2312 May 11 '15 at 07:41
  • can your try one of the methods given here: https://gist.github.com/djangofan/5112655, here is the reference post : http://stackoverflow.com/questions/16166261/selenium-webdriver-stale-element-reference-exception?rq=1 – skumar May 11 '15 at 15:46
  • These solutions will work for me without any issues. Its the page object gem that is throwing the error. – yudi2312 May 14 '15 at 11:48
  • There is already an issue logged for this https://github.com/cheezy/page-object/issues/224 – yudi2312 May 14 '15 at 12:01