ashot
ashot copied to clipboard
Only Current Screen is captured in Chrome Driver
Hi AShot Team, When I run the below java code it runs properly,but it captures only current screen. The below part of screen is not captured by this code. please see the below code :+1:
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.bbc.com");
Thread.sleep(5000);
(new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>() {
public WebElement apply(WebDriver newDriver) {
return newDriver.findElement(By.cssSelector(".wsradio__title__link"));
}
});
final Screenshot screenshot = new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG", new File("D:\\temp\\"+ "AShot_BBC_Entire.png"));
driver.quit();
Please provide the solution. It works perfectly in Firefox browser.
Hi, @shahankit783. For Chrome you should use
new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(webDriver);
because it takes only view port screenshot. Notice that you should use different AShot configurations for different browsers. For Firefox you don't need this strategy.
Hi , @pazone
Thank you for reply. For chrome driver can you please suggest what can be the possible values of "ShootingStrategies" in this case
You can find the factory of such strategies in ShootingStrategies.java. In this case viewportPasting(100)
- 100 - is a timeout interval between scrolling of viewport.
For chrome driver, it is not taking full web-page screenshot
- It overlaps body parts in screenshot.
- Also, it takes 50-70% of screenshot horizontally.
I used
new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(webDriver);
I tried using two ways. Both produce same result in Chrome. For firefox, things are working perfectly using above way.
new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(webDriver, webDriver.findElement(By.xpath("//body"));
take anything, //body OR //div[@class='<element-class-name-for-complete-container']
Hi Ashot Team,
I am trying to capture the full page screenshot in chrome using following code but its only taking part of it, like it is almost cutting 25% of right and 30% bottom part. Please see attached image which is produced from Ashot. However I have 2 more columns in right and one graph in bottom which is got cut.
Please help.
Hello, @javedansari1983. Could you please provide your code when you are taking screenshot?
Here is my code which I am using for chrome. However I have also tried with firefox (v46) but it just takes top part screenshot and paste 4 times below and create the screenshot.
public void takeScreenshot() throws IOException { System.setProperty("webdriver.chrome.driver", "C:\Javed_Projects\LongHorn\LongHorn\drivers\chromedriver.exe"); WebDriver myDriver = new ChromeDriver(); myDriver.manage().window().maximize(); myDriver.get("C:/Javed_Projects/LongHorn/LongHorn/src/test/java/JSon/index.html"); Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(2000)).takeScreenshot(myDriver);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File("C:/Javed_Projects/LongHorn/LongHorn/CustomEmailReport/FullPageScreenshot.png"));
myDriver.quit();
}
Please Help.
Hey Ashot Team,
I have got the full page screenshot using firefox v46 without using any strategies. Please help me for chrome.
Hey Ashot Team,
Can you please tell the solution for chrome??
Hey Ashot team,
Unfortunately I din't get answer to my last comment which is getting proper screenshot with chrome.
However I am using firefox for now and got in to another problem when I am running this using jenkins.
It works fine when I run it using eclipse. But it fails to take correct screenshot when I am running the same project using jenkins. See the attached screenshot which is got produced running the project using jenkins.
@javedansari1983 To be honest, I can not understand the problem. At least I should know your Selenium configuration on Jenkins. Obviously it differs of your local firefox. What is the actual problem in your attached screenshots?
Thanks for responding.
I am using selenium 2.53 and jenkins 2.32.3.
The problem is that the html opens up as screenshot #1 in browser either I open it manually or I run the project through eclipse. However when I am invoking this project through Jenkins it produces screenshot#2.
Screenshot#1:
Screenshot#2:
Please help.
@javedansari1983 Firefox on Jenkins has smaller window size. The bast approach is to make you window size predictable. Just try to set you preferred window size before your test driver.manage().window().setSize(new Dimension(x, y));
@pazone
Hey, I am also facing same issue. Vertical scroll for full page screengrab is good, but horizontally, the image gets chopped and I see only 70-75% screen. When I take just the visible screen screenshot, I get proper width. This is my method for the full screen image:
` public static String captureFullScreen(String screengrabName, WebDriver driver) throws IOException {
int veiwPortWidth = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width;
System.out.println("veiwPortWidth: "+veiwPortWidth);
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000))
.takeScreenshot(driver);
dest = screengrabFolder + screengrabName + ".png";
File destination = new File(dest);
ImageIO.write(fpScreenshot.getImage(), "PNG", destination);
System.out.println("Screengrab link: " + dest);
return dest;
}`
I am also attaching the image of the chopped view.
@jiggy-rc Hi. You can solve it by adjusting your window width. driver.manage().window().setSize(new Dimension([over100500]))
. This workaround will help right now. Also it is possible to create VerticalAndHorisontalPastingStrtegy
. But it going to take some time. I'll try to create it but it's hard to predict when it will be done.
@pazone ,
Thank you so much for the quick response, but when I used driver.manage().window().setSize(new Dimension(1000,725));
I got the attached :
which kinda is worst =/
@jiggy-rc Try webDriverRule.getDriver().manage().window().maximize()
or new Dimension(2000,725)
@pazone ,
No luck. This is what I get:
When dimensions are new Dimension(2000,725)
When dimensions are new Dimension(2500,800)
Use Firefox 46.0.1 and use firefox driver to take screenshot. This is what I am using and screenshot is coming properly for me. Try it and let me know. Code Snippet: import ru.yandex.qatools.ashot.AShot; import ru.yandex.qatools.ashot.Screenshot; WebDriver myFFDriver = new FirefoxDriver(); Screenshot fpScreenshot = new AShot().takeScreenshot(myFFDriver);
@javedansari1983 Cannot. Company wants to use chrome only. =/
@jiggy-rc It looks like a problem with you Selenium grid configuration. For some reasons browser window size is limited and your page doesn't fit in it. Do you use Selenium grid?
@pazone Nope. Just regular Selenium webdriver. And our page is sized dynamically. So it will fit in any size window. Window is getting re-sized correctly, but for any size, only 75% (horizontally) page is being captured.
I had problem similar to one described above where either pasting startegy wasn't working correctly by producing screenshots where some parts overlap others or where width is incorrect. It was solved by switching from setting webdriver window size to maximize(); It seems that Ashot is not working correctly with drivers that are not maximized.
@jiggy-rc Which OS are you using? And which DPR? If you have the retina display, you should set the dpr
to AShot.
Actually, since I've received notification from this thread: It's worth mentioning that you would receive incorrect screenshot if screen scaling is set to more than 100%, could be checked in Display settings in Windows.
@pazone ,
Win7 Chrome Version 60.0.3112.101 (Official Build) (64-bit)
Dear Ashot Team, I have tried below code but still the screenshot is taken only for visible part of the web page and not for the scrolled down page.. PLease help!!
driver.manage().window().setSize(new Dimension(1000,725));
Also tried: driver.manage().window().maximize();
doesnt work. I am using Chrome.
@apathan123 , for full screen, u can use this code. But the issue is only 75-80% of the hotizontal screen is captured (vertically 100% is captured).
` public static String captureFullScreen(String screengrabName, WebDriver driver) throws Exception {
Thread.sleep(1500); // This wait is to pause the code till the page
// completely loads before taking screengrab.
driver.manage().window().setSize(new Dimension(1500, 1000));
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000))
.takeScreenshot(driver);
dest = screengrabFolder + screengrabName + ".png";
File destination = new File(dest);
ImageIO.write(fpScreenshot.getImage(), "PNG", destination);
System.out.println("Screengrab link: " + dest);
driver.manage().window().maximize();
return dest;
}
`
@pazone , My system is Win7, 64 bit, ChromeVersion 60.0.3112.113 (Official Build) (64-bit) ... nothing fancy ... and I am still not getting 100% image horizontally.
@jiggy-rc
It did not work. Actually viewportpasting is throwing an exception for me so had to remove that line. raised new issue for that error. #107