简体   繁体   English

我可以在没有网页检测牵线木偶的情况下使用 geckodriver 运行 Selenium 吗?

[英]Can I run Selenium using geckodriver without a webpage detecting marionette?

I want to use FirefoxDriver with Selenium but I keep getting detected by webpages.我想将 FirefoxDriver 与 Selenium 一起使用,但我一直被网页检测到。 When I add the following code当我添加以下代码时

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

The webpages cant't detect I'm using geckodriver but I can't use Selenium automation and that's my problem.网页无法检测到我正在使用 geckodriver,但我无法使用 Selenium 自动化,这就是我的问题。 I need the automation without detection.我需要没有检测的自动化。

QUESTIONS:问题:

  1. Can I change the setCapabilites on/off while the driver is running?我可以在驱动程序运行时打开/关闭 setCapabilites 吗?
  2. Is it easier to do this using ChromeDriver?使用 ChromeDriver 是否更容易做到这一点?

Using FirefoxDriver with Selenium but getting detected is quite common now as:FirefoxDriverSelenium一起使用但被检测到现在很常见,因为:

Selenium identifies itself硒标识自己

You can find a detailed discussion in How to make Selenium script undetectable using GeckoDriver and Firefox through Python?您可以在如何通过 Python 使用 GeckoDriver 和 Firefox 使 Selenium 脚本无法检测到中找到详细讨论


Marionette木偶

As per the documentation, Marionette , is the automation driver for Mozilla's Gecko engine.根据文档, Marionette是 Mozilla 的 Gecko 引擎的自动化驱动程序。 It can remotely control the UI and the internal JavaScript of a Gecko platform, such as Mozilla Firefox.它可以远程控制 Gecko 平台(如 Mozilla Firefox)的 UI 和内部 JavaScript。 It can control both the chrome (ie menus and functions) or the content (the webpage loaded inside the browsing context), giving a high level of control and ability to replicate user actions.它可以控制镶边(即菜单和功能)或内容(在浏览上下文中加载的网页),从而提供高级别的控制和复制用户操作的能力。 In addition to performing actions on the browser, Marionette can also read the properties and attributes of the DOM.除了在浏览器上执行操作外,Marionette 还可以读取 DOM 的属性和属性。 Now, shares much of the same API as Selenium/WebDriver , with additional commands to interact with Gecko's chrome interface.现在, Selenium/WebDriver共享大部分相同的 API,以及与 Gecko 的 chrome 界面交互的附加命令。 Its goal is to replicate what Selenium does for web content, ie to enable the tester to have the ability to send commands to remotely control a user agent .它的目标是复制 Selenium 对 Web 内容所做的事情,即使测试人员能够发送命令来远程控制用户代理

We have also discussed in details about Why Firefox requires GeckoDriver?我们还详细讨论了为什么 Firefox 需要 GeckoDriver? within this thread在这个线程内

Finally, in the discussion Difference between webdriver.firefox.marionette & webdriver.gecko.driver we discussed about initializing Firefox sessions using legacy Firefox 47.x browsers and GeckoDriver enabled Firefox >47.x browsers.最后,在讨论webdriver.firefox.marionette 和 webdriver.gecko.driver 之间差异时,我们讨论了使用旧版 Firefox 47.x 浏览器和启用GeckoDriver 的Firefox > 47.x 浏览器初始化Firefox会话。 The conclusion was when using Firefox browsers > v77.x you have to mandatorily use GeckoDriver which extensively uses the marionette .结论是,当使用 Firefox 浏览器 > v77.x 时,您必须强制使用GeckoDriver ,它广泛使用了牵线木偶 So configuring marionette as false won't help us out.因此,将marionette配置为false对我们没有帮助。 While using the latest version of , and , you have to use the marionette by default.在使用最新版本的,您必须默认使用牵线木偶

If you still want to initialise a Firefox browsing session without using marionette you need to configure "marionette" to false as follows:如果您仍然想在不使用marionette 的情况下初始化Firefox浏览会话,则需要将"marionette"配置为false ,如下所示:

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();

You can find a couple of relevant discussions in:您可以在以下位置找到一些相关讨论:


The other questions:其他问题:


Outro奥特罗

Here you can find a detailed discussion on Which Firefox browser versions supported for given Geckodriver version?在这里您可以找到有关给定 Geckodriver 版本支持哪些 Firefox 浏览器版本的详细讨论

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SessionNotCreatedException:尝试通过 Java 使用 Selenium GeckoDriver 和 Firefox 运行命令而不建立连接错误 - SessionNotCreatedException: Tried to run command without establishing a connection error using Selenium GeckoDriver and Firefox through Java 使用 GeckoDriver 和 Firefox 通过 Selenium 和 Java 的此会话警告将忽略 Marionette-WARN-TLS 证书错误 - Marionette-WARN-TLS certificate errors will be ignored for this session warning using GeckoDriver and Firefox through Selenium and Java 我们可以让selenium webdriver等到用户在运行时点击网页链接而不使用隐式等待吗? - Can we make selenium webdriver to wait until user clicks on a webpage link at run-time without using implicit wait? 没有浏览器我可以运行Selenium网格吗? - Can I run Selenium grid without browsers? 如何使用 Geckodriver 在 Selenium 中禁用 Firefox 登录? - How do I disable Firefox logging in Selenium using Geckodriver? 无法使用 Selenium(3.11)、GeckoDriver(0.24.0)、Firefox(57 version) 运行 selenium java 脚本 - Not able to run selenium java script using Selenium(3.11), GeckoDriver(0.24.0), Firefox(57 version) Firefox不是使用Geckodriver和Selenium推出的 - 它适用于Chrome - Firefox is not launched using Geckodriver and Selenium - It works with Chrome 如何使用 GeckoDriver Firefox 和 Selenium 下载文件? - How to download files using GeckoDriver Firefox and Selenium? 如何在带有硒2.53.0的geckodriver上使用最新的Firefox浏览器运行硒脚本? - How to run selenium script with latest firefox browser on geckodriver with selenium 2.53.0? 没有Webdriver的情况下,我可以在真正的浏览器中运行selenium 2吗? - can I run selenium 2 on real browser without webdriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM