java - Can't close a print dialogue while clicking print button using javascriptexecutor in selenium Web driver firefox -


i working on automate functional testing using selenium web driver. came across scenario in need click print button on window (say a) open new window (say b). print dialogue got popped window b. need close print dialogue using java script executor.

i have tried this. did not work. code:

public void handleprintbuttonscenario { string parentwindow_a = driver.getwindowhandle(); //get current window handle printbutton().click(); //clicking print button  //switch focus of web driver newly opened window b  (string winhandle : driver.getwindowhandle()) {  driver.switchto().window(winhandle); }  //closing printdialoge closewindowbyjs();  driver.close();// closing window b  driver.switchto().window(parentwindow_a); // switching focus window  }  public void closewindowbyjs() {     javascriptexecutor js = (javascriptexecutor) driver;     string script = "window.onbeforeunload = null;" + "window.close();";     js.executescript(script); } 

right happened print dialogue , window b closed when execute scenario first time calling method closewindowbyjs(). got exception @ line driver.close() stating no such window found.

but when rerun scenario i.e. second time neither print dialogue nor window b closed. focus got changed , scenario running properly.

but need close print dialogue first using javascriptexecutor , close window b. dont need close both calling closewindowbyjs(). after need switch focus window a.

please help?

use autoit download exe record click on button , record code execute code of autoit same java script executator

your driver.close() should after code of switch window()

this should help


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -