Reputation: 31
I am automating a webpage that has an 'Exit Application' button. Upon clicking this button the browser is closed.
How can I verify that once clicking this button that the browser is closed?
Upvotes: 2
Views: 2620
Reputation: 1233
Selenium has no readymade method to check if browser is open or close, but there is a workaround to this. You can try doing this:
/*
* returns true if browser is open, else retrurns false
*/
public boolean isBrowserOpen() {
try {
driver.getTitle(); //can also use driver.getCurrentUrl()
return true;
}
catch(Exception e) {
return false;
}
}
And then in your method, add this line
if(!isBrowserOpen())
System.out.println("Browser was still open");
Upvotes: 1
Reputation: 1196
Hope below code works for your case.
try {
driver.getTitle();
System.out.println("Browser Window is still exist");
}
catch (Exception e) {
System.out.println("Brower window is closed");
}
Upvotes: 1
Reputation: 686
ProcessBuilder builder = new ProcessBuilder();
builder.command("tasklist");
Process process = builder.start();
String string = toString(process.getInputStream());
// find ie process name by regexp
Upvotes: 0