当前位置: 首页 > 知识库问答 >
问题:

如何从Selenium执行Firefox开发人员控制台命令?

宗政小林
2023-03-14

我希望从Selenium java脚本中执行Firefox的屏幕截图--fullpage命令。

该命令在使用Firefox拍摄整页截图中有文档说明

有可能吗?

共有1个答案

江俊能
2023-03-14

您只需从Java代码中获取一个截图即可。以下答案:https://stackoverflow.com/a/3423347/8020699

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

这个家伙建议使用一个叫做aShot的库来进行全页截图。这是aShot罐子的链接。以下是他给出的代码:

import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

public class FullPageScreenshot {
    public static void main(String args[]) throws Exception{
        //Modify the path of the GeckoDriver in the below step based on your local system path
        System.setProperty("webdriver.gecko.driver","D://Selenium Environment//Drivers//geckodriver.exe");
        // Instantiation of driver object. To launch Firefox browser
        WebDriver driver = new FirefoxDriver();
        // To oepn URL "http://softwaretestingmaterial.com"
        driver.get("http://www.softwaretestingmaterial.com");
        Thread.sleep(2000);
        Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
        ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
    }
}
 类似资料:
  • 我试图用Python通过Selenium打开firefox控制台。如何使用python Selenium打开firefox控制台?有没有可能把钥匙发给司机或者类似的东西?

  • ... browser=webdriver.chrome(executable_path=“c:\chrm\chromedriver.exe”)browser.get(“https://www.facebook.com/groups/gnexus5/) ... 我正在使用ChromeDriver

  • 代码是很容易出现错误的。你也很可能犯错误……哦,我在说什么?只要你是人,你 一定 会犯错误(在写代码的时候),除非你是 机器人。 但在浏览器中,默认情况下用户是看不到错误的。所以,如果脚本中有错误,我们看不到是什么错误,更不能够修复它。 为了发现错误并获得一些与脚本相关且有用的信息,浏览器内置了“开发者工具”。 通常,开发者倾向于使用 Chrome 或 Firefox 进行开发,因为它们有最好的开

  • 我尝试了几种方法通过selenium(使用python)在Firefox中打开控制台,但这些方法都不起作用,尽管我没有得到任何故障排除,除了最后一个。 Selenium 3.141.0、Firefox 68.0、geckodriver-v0.24.0-win64

  • 我有一个 .NET Core 控制台应用程序并运行了 。但是,我不知道如何从命令行运行应用程序。有什么提示吗?