简体   繁体   English

对不存在的变量进行对象检查以进行文档检查

[英]Object check on non existing variable for document check

I have a one liner Js for Selenium tests that checks if the page is done loading. 我有一个用于硒测试的衬板Js,用于检查页面是否已完成加载。

true  === ((typeof Ext.Ajax != 'undefined' && Ext.Ajax.isLoading()) || (jQuery != 'undefined' && jQuery.active) || document.readyState != 'complete')

All other Java/Selenium ways to check are NOT compatible with our setup line of IE FF and Chrome tests (crap IE). 其他所有Java / Selenium检查方式均与我们的IE FF和Chrome测试设置程序(废旧IE) 兼容。 We spent like 3 months of trying, so Selenium checks are out of question. 我们花了大约3个月的时间进行尝试,因此硒检查毫无疑问。 This check is ok most of the time, except when the Extjs variable is not set in that page then i get the dreaded Ext is not defined exception and selenium crashes. 大多数时候都可以进行此检查,除非未在该页面中设置Extjs变量,然后我得到了可怕的Ext未定义异常和硒崩溃。 Is there an another way to check for a variable in one liner which can do nested checks i tried object checks like in 还有另一种方法可以在一个内衬中检查变量是否可以执行嵌套检查,我尝试了对象检查,例如

javascript test for existence of nested object key JavaScript测试是否存在嵌套对象键

But when i do 但是当我这样做

((Ext|| {}).Ajax ((Ext || {})。Ajax

I still get the exception. 我仍然得到例外。

在阅读完其余文章后,我遇到了一个解决方案:

(typeof Ext != 'undefined' ? Ext : {}) 

这也应该起作用:

(window.Ext || {}).Ajax

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

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