【问题标题】:How can selenium run in IE do not show the browser windows?selenium 在 IE 中运行如何不显示浏览器窗口?
【发布时间】:2016-08-29 08:22:19
【问题描述】:

操作系统为windows10,编程语言为JAVA,浏览器为IE11。 selenium 怎么能在没有浏览器窗口的情况下运行?

【问题讨论】:

  • 我不是 Windows 专家,但在 Linux 上,启动专用 X 服务器并在其中启动测试会有所帮助。你能做类似的事情吗,例如使用 VNC 或 RDP?
  • 试试这个。 triflejs.org 它使用 PhantomJS,底层是著名的无头浏览器(Selenium 支持 Phantom)。不过我还没试过。
  • 有没有关于如何在 selenium 中使用 triflejs 的文档?

标签: selenium selenium-webdriver selenium-iedriver


【解决方案1】:

你可以使用phantonjs、HtmlUnitDriver或者headless chrome

对于 HtmlUnitDriver

WebDriver driver=new HtmlUnitDriver();
driver.get("http://google.com"); 

对于phantomjs,首先下载ghostdriver并使用

System.setProperty("phantomjs.binary.path", "E:\\phantomjs-2.1.1-windows\\phantomjs.exe");  
WebDriver driver = new PhantomJSDriver();   
driver.get("http://google.com");  

对于 chrome,请下载 Chromedriver 并使用

System.setProperty("webdriver.chrome.driver","E:/software and tools/chromedriver_win32/chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless");
driver.get("http://google.com"); 

【讨论】:

    【解决方案2】:

    使用 phantomjs、htmlunit 等无头浏览器与 selenium webdriver 一起运行。

    【讨论】:

      猜你喜欢
      • 2021-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 2019-03-30
      • 1970-01-01
      相关资源
      最近更新 更多