我如何将无头浏览器与 Selenium 和 C#.Net 一起使用

How can i use Headless Browser with Selenium and C#.Net

如何将无头浏览器与 Selenium 和 C#.Net 一起使用。

我是 selenium 的新手,所以可以帮助我。

虽然市场上有多种此类无头浏览器,但以下是最受欢迎的浏览器:

  • 无头Chrome
  • PhantomJS
  • SlimerJS
  • TrifleJS
  • HTMLUnit 驱动程序

伪代码:

  package chrome;
           public class HeadlessTesting {
                public static void main(String[] args) throws IOException{
                    System.setProperty("webdriver.chrome.driver",
                            "ChromeDriverPath");
                    ChromeOptions options = new ChromeOptions();
                    options.addArguments("headless");
                    options.addArguments("window-size=1200x600");
                    WebDriver driver = new ChromeDriver(options);
                    driver.get("https://contentstack.built.io");
                    driver.get("https://www.google.co.in/");
                    System.out.println("title is: " + driver.getTitle());
                    File scrFile = ((TakesScreenshot) driver)
                            .getScreenshotAs(OutputType.FILE);
                    FileUtils.copyFile(scrFile, new File("pathTOSaveFile"));
                    driver.quit();
                }
            }