title: Waiting for a element to load using watir
body: <p>I just migrated to ruby 1.9.3 from 1.8.. Instead of using the wait methods I had a method of my own that used to check for a element to load and it used to work perfectly on 1.8.7. But after I upgraded to ruby 1.9.3 the method fails at random times with the below exception.</p>
  
  <blockquote>
    <p>unknown property or method: <code>parentelement'
        HRESULT error code:0x80070005
          Access is denied.
        C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-2.0.4/lib/watir/element.rb:168:in</code>method_missing'
        C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-2.0.4/lib/watir/element.rb:168:in <code>parent'
        D:/Ruby_193/Watir/script/script1.rb:78:in</code>block (2 levels) in test_script1'
        D:/Ruby_193/Watir/lib/helper.rb:494:in <code>call'
        D:/Ruby_193/Watir/lib/helper.rb:494:in</code>load_finished'
        D:/Ruby_193/Watir/lib/helper.rb:488:in <code>wait_for_pageload'
        D:/Ruby_193/Watir/script/script1.rb:78:in</code>block in test_script1'
        D:/Ruby_193/Watir/lib/helper.rb:526:in <code>call'
        D:/Ruby_193/Watir/lib/helper.rb:526:in</code>run_step'
        D:/Ruby_193/Watir/script/script1.rb:71:in `test_script1'</p>
  </blockquote>
  
  <p>The code at line no. 78 in my script1.rb is</p>
  
  <pre><code>77: browser.button(:value, "Generate").click
  78: wait_for_pageload( lambda {browser.cell(:text,"Coversheet").parent.link(:text,"template").exists? })
  </code></pre>
  
  <p>which calls the wait_for_pageload method in the helper.rb file</p>
  
  <pre><code>482:def wait_for_pageload(page_lambda = nil, &amp;page_closure)
  483:  script = "window.frames.frame::1.document.enabled"
  484:  page_lambda = page_closure if block_given?
  485:  count = 0
  486:  load_limit = 1200
  487:  sleep_time = 0.1
  488:  sleep sleep_time until load_finished(script, page_lambda) || (count +=1) &gt; load_limit
  489:  raise "Unable to load page in over #{load_limit} tries (#{sleep_time * load_limit} seconds)" if count &gt; load_limit
  490:end
  </code></pre>
  
  <p>the wait_for_pageload method in-turn calls the load_finished method and passes the javascript variable and the page_lambda to the method</p>
  
  <pre><code>493:def load_finished(script, page_lambda)
  494:  page_lambda.nil? ? browser.execute_script(script).to_s == "true" : page_lambda.call()
  495:end
  private :load_finished
  </code></pre>
  
  <p>Sorry I will not be able to provide a link to the site or html.</p>
  
  <p>What happens is when I click on the Generate button(line no 77.) the page refreshes and a template link is displayed. The time taken to display the template link varies each time. So I am checking if the link is displayed or not with the help of wait_for_pageload.</p>
  
  <p>But after the link is generated when I run the below code it returns true.</p>
  
  <pre><code>browser.cell(:text,"Coversheet").parent.link(:text,"template").exists?
  </code></pre>
  
  <p>So I am sure its not an error with that part. I did a little research and found that there have been changes in proc and lambda in 1.9.3 and I guess the issue occurs at the line no. 494 <code>page_lambda.nil? ? browser.execute_script(script).to_s == "true" : page_lambda.call()</code></p>
  
  <p>I am clueless about what changes in 1.9.3 are causing this issue. It would be of great help if anyone can help me.</p>