简体   繁体   English

Watir的ready_state方法抛出“ JavaScript错误”

[英]Watir's ready_state method throws “JavaScript error”

I am testing a website on IE11 using watir-webdriver . 我正在使用watir-webdriver在IE11上测试网站。 I wrote a method that waits until page is fully loaded 我写了一个方法,等待页面完全加载

def page_loaded?
 until @browser.ready_state.eql? 'complete' do
  sleep 1
 end
end

But sometimes I get "JavaScript error" and on fail screenshot I see that some elements of a page are not loaded, which means that my method did not wait until page is loaded. 但是有时我会收到"JavaScript error"并且在失败的屏幕截图上,我看到页面的某些元素未加载,这意味着我的方法没有等到页面加载完毕。 how can I handle "JavaScript error" ? 如何处理"JavaScript error" Is it exception? 是例外吗? If yes, what class of exceptions is it? 如果是,那是什么类别的例外? Help is appreciated. 感谢帮助。

That method is already built into Watir . 该方法已内置到Watir中 That being said, the notion of a "page finishing loading" is becoming increasingly meaningless with today's dynamic websites. 话虽如此,“页面整理加载”的概念在当今的动态网站中变得越来越没有意义。

I'd need to see a full backtrace of the error and ideally what your code is specifically trying to do when it happens in order to give a specific answer to your question of the specific error. 我需要查看该错误的完整回溯,并且理想情况下,代码应该在发生错误时特别尝试执行什么操作,以便为您对特定错误的问题提供特定的答案。 The generic answer, and the one I'm most likely to give you even after I've seen your code, is to not rely on document ready state. 通用答案,即使在我看到您的代码后,我最有可能给您的答案是,不要依赖文档准备就绪状态。 Make liberal use of Watir's wait_until_present & when_present methods to be sure you can interact with the elements before you try to do so. 充分利用Watir的wait_until_presentwhen_present方法,以确保在尝试进行操作之前可以与元素进行交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM