简体   繁体   中英

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.

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). We spent like 3 months of trying, so Selenium checks are out of question. 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. 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

But when i do

((Ext|| {}).Ajax

I still get the exception.

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

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

这也应该起作用:

(window.Ext || {}).Ajax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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