javascript - selenium-webdriver npm: how to switch focus to new window from target="_blank" -


in building bank of selenium tests have bit of brick wall javascript selenium-webdriver npm.

this particular test requires selenium check target="_blank" link works querying content of page loaded. cannot seem selenium shift focus new window.

from reading docs , s.o. seem should work:

driver.switchto().defaultcontent(); 

but nothing. simple test:

//1 load url     driver.get( testconfig.url + '/britain/england/cornwall/hotelx' ).then(function(){         //2 find link , click         driver.findelement(by.css('.details-web')).click().then(function(){             //3 timeout of 10 seconds allow other window open             settimeout(function(){                 //switch focus new window (ie current active window)                 driver.switchto().defaultcontent().then(function(){                     //5 wait till new el visible                     driver.wait( function(){                         return driver.iselementpresent(by.css("#infinite-footer"));                     }, testconfig.timeout).then(function(){                         driver.close();                         if( callback ){                             callback( callback );                         }                     });                 });             },10*1000);         });     }); 

i found post: selenium webdriver - switch child window without name in java, had go @ translating javascript didn't far.

has else managed javascript selenium-webdriver?#

thanks, john

attempted fix @stanjer, undefined not function when trying run foreach...? or "referenceerror: availablewindows not defined "

//1 load url         driver.get( testconfig.url + '/britain/england/cornwall/hotelx' ).then(function(){             //2 find link , click             driver.findelement(by.css('.details-web')).click().then(function(){                 var parent = driver.getwindowhandle();                 driver.sleep(1000);                 var availablewindows = driver.getallwindowhandles();                 var newwindow = null;                 availablewindows.foreach(function(window) {                     console.log( window );                     if (window != parent) {                         newwindow = window;                     }                 });                 if (newwindow != null) {                     driver.switchto().window(newwindow);                      driver.wait( function(){                         return driver.iselementpresent(by.css("#infinite-footer"));                     }, testconfig.timeout).then(function(){                         driver.close();                         if( callback ){                             callback( callback );                         }                     });                 }             });         }); 

the console.log of availablewidnows:

{ closure_uid_233425945: 273,   flow_:    { events_: {},      closure_uid_233425945: 1,      activeframe_:       { events_: [object],         closure_uid_233425945: 29,         flow_: [circular],         parent_: [object],         children_: [object],         lastinsertedchild_: [object],         pendingtask_: null,         islocked_: true,         isblocked_: false,         pendingcallback: false,         pendingrejection: false,         cancellationerror_: null },      schedulingframe_:       { events_: {},         closure_uid_233425945: 204,         flow_: [circular],         parent_: [object],         children_: [object],         lastinsertedchild_: [object],         pendingtask_: null,         islocked_: false,         isblocked_: false,         pendingcallback: false,         pendingrejection: false,         cancellationerror_: null },      shutdowntask_: null,      eventlooptask_: null,      hold_:       { _idletimeout: 2147483647,         _idleprev: [object],         _idlenext: [object],         _idlestart: 410669389,         _ontimeout: [function: wrapper],         _repeat: true },      yieldcount_: 2 },   stack_: null,   parent_:    { closure_uid_233425945: 271,      flow_:       { events_: {},         closure_uid_233425945: 1,         activeframe_: [object],         schedulingframe_: [object],         shutdowntask_: null,         eventlooptask_: null,         hold_: [object],         yieldcount_: 2 },      stack_: { [task: webdriver.getallwindowhandles()] name: 'task' },      parent_: null,      callbacks_: [ [object] ],      state_: 'pending',      handled_: true,      pendingnotifications_: false,      value_: undefined },   callbacks_: null,   state_: 'pending',   handled_: false,   pendingnotifications_: false,   value_: undefined } 

so, if want exact copy of code in js:

parent = driver.getwindowhandle();  driver.sleep(1000); var availablewindows = driver.getallwindowhandles(); var newwindow = null; availablewindows.foreach(function(window) {     if (window != parent) {         newwindow = window;     } } if (newwindow != null) {     driver.switchto().window(newwindow); } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -