Skip to main content

Posts

Showing posts with the label screenshot

Screenshot using Chrome DevTools

1. Open a Chrome browser. 2. Open Dev Tools (Press F12). 3. Press CTRL+SHIFT+P (in windows) or cmd+SHIFT+P (in mac). 4. Type "screenshot" into the Command Menu and you will see options like "Capture area screenshot", "Capture full-size screenshot", Capture node screenshot" and "Capture screenshot". 5. Select your desired option and hit enter. Done... If you wish to, you can also emulate a device mode first and then take the screenshot- this way it will capture as per the device dimensions. Isn't it really handy when you want to take the screenshot of the entire page on any device like iPhone X?

Full page screenshot- Selenium 4 (Firefox for now)

Full page screenshot— Using Selenium 4 (alpha 2 or greater), now we can take the full page screenshots with getFullPageScreenshotAs() method in the Firefox. But instead of typecasting it to ‘TakesScreenshot’ interface, we need to typecast it to FirefoxDriver instance. File src = ((FirefoxDriver) driver).getFullPageScreenshotAs(OutputType.FILE); I checked but it looks like this method is not available for Chrome or any other browsers yet. hashtag # seleniumautomation hashtag # automationtesting hashtag # tipsandtricks hashtag # firefox hashtag # screenshot hashtag # selenium4

Screenshot of a specific element:: Selenium 3.x Vs Selenium 4

getScreenshotAs for WebElement was not supported until Selenium 3.x, so we had to take a long route like taking a complete viewable area screenshot and then cropping the part where we have our element by using getLocation, getSize, getWidth, getHeight and then finally getSubimage method like shown in image 1. But from Selenium 4 (at least alpha 3) onwards, getScreenshotAs is also supported for WebElement like this: public static void eleScreenshot() throws InterruptedException, IOException { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(" https://in.linkedin.com/ "); if(driver instanceof ChromeDriver) { File src = driver.findElement(By.xpath("/html/body/nav/a[1]/li-icon")).getScreenshotAs(OutputType.FILE); FileHandler.copy(src, new File("D:\\Learning_Automation\\Practise\\Image1.png")); } } Note* I u