【问题标题】:avoid opening the browser while running selenium webDriver test cases避免在运行 selenium webDriver 测试用例时打开浏览器
【发布时间】:2013-11-16 21:10:17
【问题描述】:

我从你们那里得到了很多帮助,我真的很高兴。已经通过了这些聚会,

web page source downloaded through Jsoup is not equal to the actual web page source

How to download a Web page source using Selenium

现在我终于来到了最后一次聚会(希望如此)

在运行 selenium 测试用例时,像这样,

 WebDriver driver = new FirefoxDriver();
        FluentWebDriver fwd = new FluentWebDriver(driver);

        driver.manage().timeouts().implicitlyWait(5L, TimeUnit.SECONDS);
        driver.get("http://www.justdial.com/Bangalore/Tape-Dealers-%3Cnear%3E-Bangalore-City-Railway-Station/ct-12976/page-5");

       String res = driver.getPageSource();

它打开网络浏览器并开始下载页面中的所有图像,并导致从我的 java 程序下载源代码的延迟。在这种情况下如何避免打开我的浏览器?我只想要页面源和没有图形内容。因此也避免延误......请帮助!提前致谢!!

【问题讨论】:

  • 您想要一个无头驱动程序。您可以使用 HTMLUnit 驱动程序或 PhantomDriver。

标签: java selenium


【解决方案1】:

我没有使用 FluentWebDriver,但我想你可以尝试用 HtmlUnitDriver 替换 FirefoxDriver:

替换:

WebDriver driver = new FirefoxDriver();

与:

HtmlUnitDriver driver = new HtmlUnitDriver();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-03
    • 2011-09-16
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    相关资源
    最近更新 更多