QNA > I > Is It Possible To Take Screenshot Of Alert In Selenium Without Handling It?

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 :-

  1. WebDriver driver = new FirefoxDriver(); 
  2. driver.get("http://toolsqa.wpengine.com/handling-alerts-using-selenium-webdriver/"); 
  3.  
  4. driver.manage().window().maximize(); 
  5.  
  6. // This step will result in an alert on screen 
  7. WebElement element = driver.findElement(By.xpath("//*[@id='content']/p[11]/button")); 
  8.  
  9. //Java Script Executor for click the element 
  10. ((JavascriptExecutor) driver).executeScript("arguments[0].click()", element); 
  11.  
  12. Thread.sleep(2000); 
  13.  
  14. // Press the key combination of (Windows + PrintScreen) by using Robot Class 
  15. Robot rb = new Robot(); 
  16. rb.keyPress(KeyEvent.VK_WINDOWS); 
  17. rb.keyPress(KeyEvent.VK_PRINTSCREEN); 
  18. rb.keyRelease(KeyEvent.VK_PRINTSCREEN); 
  19. 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)

Di Tiga

Quali canzoni sono state le vostre suonerie? :: Come trasferire i dati di WhatsApp da un Android a iOS
Link utili