javascript加载_检测文档是否已加载JavaScript

javascript加载

If you follow me on Twitter, you've probably noticed me whining about ChromeDriver.  For some reason it seems as though tests run before the document has properly loaded, leading to transient test failures and loads of frustration.

如果您在Twitter上关注我 ,您可能已经注意到我对ChromeDriver的抱怨。 由于某种原因,似乎在正确加载文档之前就进行了测试,从而导致短暂的测试失败和沮丧。

I thought the best way to avoid these problems was to ensure the document had loaded before each test run -- that way there's no excuse for transient loading problems.  Here's the snippet I use to check if the page is ready:

我认为避免这些问题的最佳方法是确保在每次测试运行之前都已加载文档-这样就不会为暂时加载问题辩解。 这是我用来检查页面是否准备就绪的代码段:


// The basic check
if(document.readyState === 'complete') {
    // good to go!
}

// Polling for the sake of my intern tests
var interval = setInterval(function() {
    if(document.readyState === 'complete') {
        clearInterval(interval);
        done();
    }    
}, 100);


I found it ironic that for years we went looking for the ultimate "domready" script and here I am in 2015 trying to figure out if the document has completed loading.  This is why we drink.

具有讽刺意味的是,多年来我们一直在寻找最终的“ domready”脚本,而我在2015年试图弄清楚文档是否已完成加载。 这就是为什么我们喝酒。

翻译自: https://davidwalsh.name/document-readystate

javascript加载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值