【问题标题】:Can I run Selenium using geckodriver without a webpage detecting marionette?我可以在没有网页检测木偶的情况下使用 geckodriver 运行 Selenium 吗?
【发布时间】:2020-03-20 01:50:09
【问题描述】:

我想将 FirefoxDriver 与 Selenium 一起使用,但我不断被网页检测到。当我添加以下代码时

System.setProperty("webdriver.gecko.driver", "../../../../../../../usr/bin/geckodriver");
FirefoxOptions opt = new FirefoxOptions();
opt.setCapability("marionette", false);
driver = new FirefoxDriver(opt);

网页无法检测到我正在使用 geckodriver,但我无法使用 Selenium 自动化,这是我的问题。我需要无需检测的自动化。

问题:

  1. 我可以在驱动程序运行时打开/关闭 setCapabilites 吗?
  2. 使用 ChromeDriver 是否更容易做到这一点?

【问题讨论】:

    标签: java selenium marionette geckodriver firefox-marionette


    【解决方案1】:

    将 FirefoxDriver 与 Selenium 一起使用,但现在很常见,因为:

    Selenium 自我识别

    您可以在How to make Selenium script undetectable using GeckoDriver and Firefox through Python?找到详细讨论


    木偶

    根据文档,Marionette 是 Mozilla 的 Gecko 引擎的自动化驱动程序。它可以远程控制 Gecko 平台的 UI 和内部 JavaScript,例如 Mozilla Firefox。它可以控制 chrome(即菜单和功能)或内容(在浏览上下文中加载的网页),提供高级别的控制和复制用户操作的能力。除了在浏览器上执行操作之外,Marionette 还可以读取 DOM 的属性和属性。现在, 与Selenium/WebDriver 共享许多相同的 API,并具有与 Gecko 的 chrome 界面交互的附加命令。它的目标是复制 Selenium 对 Web 内容所做的工作,即使测试人员能够发送命令以远程控制用户代理。

    我们还在thread

    中详细讨论了为什么 Firefox 需要 GeckoDriver?

    最后,在Difference between webdriver.firefox.marionette & webdriver.gecko.driver 的讨论中,我们讨论了使用旧版 Firefox 47.x 浏览器和启用 GeckoDriver 的 Firefox 初始化 Firefox 会话 > 47.x 浏览器。结论是当使用 Firefox 浏览器 > v77.x 时,您必须强制使用广泛使用 ma​​rionette 的 GeckoDriver。所以将 marionette 配置为 false 对我们没有帮助。在使用最新版本的、和时,您必须默认使用木偶。

    如果您仍想在不使用 ma​​rionette 的情况下初始化 Firefox 浏览会话,则需要将 "marionette" 配置为 @987654341 @如下:

    System.setProperty("webdriver.gecko.driver", "C://path//to//geckodriver.exe");
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability("marionatte", false);
    FirefoxOptions opt = new FirefoxOptions();
    opt.merge(dc);
    FirefoxDriver driver =  new FirefoxDriver(opt);
    driver.get("https://stackoverflow.com");
    System.out.println("Application opened");
    System.out.println("Page Title is : "+driver.getTitle());
    driver.quit();
    

    您可以在以下位置找到一些相关讨论:


    其他问题:


    结尾

    在这里你可以找到关于Which Firefox browser versions supported for given Geckodriver version?的详细讨论

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-25
      • 1970-01-01
      • 1970-01-01
      • 2018-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多