简体   繁体   English

使用Selenium Java进行屏幕捕获时将显示新窗口

[英]New window displays upon screen capturing using Selenium Java

Is there a way, not to prompt a new window for your screenshot code when it is in a class ? 有没有办法在类中不为您的屏幕截图代码提示新窗口?

This is where I call the class within my code: 这是我在代码中调用类的地方:

findText(By.xpath("//*[text()='Table']")).click
pause(3)
findLink(By.cssSelector("button.btn.btn-link[aria-label='Maximize']")).click

new takesScreenshot();

findLink(By.cssSelector("button.btn.btn-link[aria-label='Dashlet Actions']")).click

This is my class code for screenshot: 这是我的屏幕截图类代码:

public class takesScreenshot   {


 {
    WebDriver driver = new ChromeDriver();
    File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(tempFile,new File( "C:\\Screenshots\\"+ "SS1" + ".png"));
       } catch (IOException e) {
        // TODO handle exception
    }

Right now when the class is called it prompts a new window that's why i cannot do screenshot for what i supposed to capture please help thanks! 现在,当该类被调用时,它会提示一个新窗口,这就是为什么我无法对应该捕获的内容进行截图,请帮助谢谢!

its because you are starting a new chrome driver instance in your takeScreenshot method. 这是因为您要在takeScreenshot方法中启动新的Chrome驱动程序实例。 Take out the line: 取出线:

WebDriver driver = new ChromeDriver();

if you need your driver instance, you may need to pass it into the takeScreenshot method 如果需要驱动程序实例,则可能需要将其传递给takeScreenshot方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM