How to handle multiple jQuery popup with selenium webdriver -
i working on java selenium webdriver 2.39, have application multiple 'processing' popup display 2-5 sec , closed automatically, depend on data. now, question how handle popup, popup jquery popup. script can work further once 3 popup gets open , process data , closed automatically. however, can not use wait time script used load testing using jmeter, hence process time may take more or less 5 sec., there way can know if popup exist or not on screen? have used below given sample code returns parent window , not identify jquery popup, using below given code can if popup exist or not, if not jquery popup. can me?
public void focusonwindow() throws exception{ int i=0; { handles=driver.getwindowhandles();//get windows iterator = handles.iterator(); if(iterator.hasnext()){ subwindowhandler = iterator.next(); if(subwindowhandler==null){ i=0; }else if(subwindowhandler!=null){ if(subwindowhandler!=parentwindowhandler){ popup = true; i=2; } } } }while(i<2); if(popup){ do{ handles=driver.getwindowhandles(); iterator = handles.iterator(); thread.sleep(500); if(iterator.hasnext()){ subwindowhandler = iterator.next(); if(subwindowhandler!=parentwindowhandler){ if(subwindowhandler==null){ string source = driver.getpagesource(); if(source==null){ i=2; } } }else { i=0; } //system.out.println("no other popup."); } }while (i<2); } }
first of all, i'll suggest not put hard wait @ all.
if aware of of element unique , part of post processing pop screen (i.e. resulted user screen) make use of selenium waitforelement() api function intelligently wait element appear , once appeared performs further actions.
take @ this link explains advantages of using it.
and java bindings selenium in place, can use -
webdriverwait wait = new webdriverwait(driver, /*seconds=*/3); elementofpage = wait.until(presenceofelementlocated(by.id("id_of_element"))); function<webdriver, webelement> presenceofelementlocated(final locator) { return new function<webdriver, webelement>() { public webelement apply(webdriver driver) { return driver.findelement(locator); } }; }
Comments
Post a Comment