I am working on selenium and wanted to have a method to check if the page has loaded completely or not.
我正在研究selenium并希望有一种方法来检查页面是否已完全加载。
For this, i wrote a method to check jquery and page is fully loaded or not. This method works fine if the page has jquery. But the code is getting stuck if the page do not have a jQuery.
为此,我写了一个方法来检查jquery和页面是否完全加载。如果页面有jquery,则此方法可以正常工作。但是如果页面没有jQuery,代码就会卡住。
Is there a way to check, prior to run the method, that the page has jquery or not.
有没有办法在运行方法之前检查页面是否有jquery。
I referred this link, but i could not implement it.
我提到了这个链接,但我无法实现它。
2 个解决方案
#1
1
The second answer to the question you linked to is actually the better one. The code in the accepted answer will throw a reference error if JQuery is not defined.
你联系到的问题的第二个答案实际上是更好的答案。如果未定义JQuery,则接受的答案中的代码将引发引用错误。
My preference would be to use the same test I use to check for any object:
我的偏好是使用我用来检查任何对象的相同测试:
if (typeof jQuery !== 'undefined' && jQuery !== null) { ... }
#2
0
simply we can use
我们可以使用
if(jQuery){
//jquery object exists
}else{
//NO jquery object
}
#1
1
The second answer to the question you linked to is actually the better one. The code in the accepted answer will throw a reference error if JQuery is not defined.
你联系到的问题的第二个答案实际上是更好的答案。如果未定义JQuery,则接受的答案中的代码将引发引用错误。
My preference would be to use the same test I use to check for any object:
我的偏好是使用我用来检查任何对象的相同测试:
if (typeof jQuery !== 'undefined' && jQuery !== null) { ... }
#2
0
simply we can use
我们可以使用
if(jQuery){
//jquery object exists
}else{
//NO jquery object
}