Reputation: 553
Consider the below code:
getCurrentUrl(driver);
driver.close();
getCurrentUrl(driver);
public void getCurrentUrl (WebDriver driver) {
if (driver window is not closed)
System.out.println(driver.getCurrentUrl());
else
System.out.println("Window is not available");
}
Please let me know how to perform the "driver window is not closed" check in Java.
Upvotes: 0
Views: 963
Reputation: 14748
hmmm ... Consider this just as a guess. But I feel like that when you call driver
variable after you close it, you can get NullPointerException
because it will be null
But anyway. I would implement it like this:
public void getCurrentUrl (WebDriver driver) {
try {
System.out.println(driver.getCurrentUrl());
} catch (Exception e) { // the most top one
System.out.println("Window is not available");
}
}
There is possibly better and cleaner way of doing it. But I am not Java programmer and my gut feeling tells me this will work
Upvotes: 1