I am trying to capture a snapshot from a large tableau report that has a huge iframe. In order to capture the full screen I need to zoom out. With a regular url pages the following code work perfectly, but when it comes to iframe
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.body.style.zoom = '50%'");
Doesn't work its charm, it zoomed the iframe container to 50% but the content text size stays the same.
Then I added
driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
Which help directed the zoom to that iframe specifically, but triggered a scroll.
Here is the code:
@Component
public class TableauReportingPage {
@Autowired
private BrowserCommands browserCommands;
@Autowired
private WebDriverService webDriverService;
public void openExistingResource(String url) throws Exception{
WebDriver driver = webDriverService.openNewBrowser();
driver.manage().window().setSize(new Dimension(1650,950));
driver.navigate().to(url);
Thread.sleep(20000);
driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
Thread.sleep(20000);
// for(int i=0; i<6; i++){
// System.out.println(i);
// new Actions(driver)
// .sendKeys(Keys.CONTROL).sendKeys(Keys.SUBTRACT)
// .perform();
// browserCommands.findElementsById("viz-client-container").
// sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));
// }
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.body.style.zoom = '50%'");
Thread.sleep(20000);
}
public File getScreenshot(){
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return browserCommands.getScreenshot();
}
}
here is the before picture: enter image description here
here is after executing the code: enter image description here
Any idea how to code and zoom iframe properly to review all objects for screenshot?