Is it possible to take screenshot of alert in selenium without handling it?
If you are talking about only Selenium WebDriver then answer is “No”
But when you use Robot Class in the Selenium Code then answer is “Yes”
Try to understand this code :-
- WebDriver driver = new FirefoxDriver();
- driver.get("http://toolsqa.wpengine.com/handling-alerts-using-selenium-webdriver/");
- driver.manage().window().maximize();
- // This step will result in an alert on screen
- WebElement element = driver.findElement(By.xpath("//*[@id='content']/p[11]/button"));
- //Java Script Executor for click the element
- ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element);
- Thread.sleep(2000);
- // Press the key combination of (Windows + PrintScreen) by using Robot Class
- Robot rb = new Robot();
- rb.keyPress(KeyEvent.VK_WINDOWS);
- rb.keyPress(KeyEvent.VK_PRINTSCREEN);
- rb.keyRelease(KeyEvent.VK_PRINTSCREEN);
- rb.keyRelease(KeyEvent.VK_WINDOWS);
Note :- (Windows + PrintScreen) shortcut keys work in Window 8, 8.1. and 10 but i’m not sure about Window 7
This code is working you can check at your end
Happy Automation :-)(y)