[英]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:问题:
Using FirefoxDriver with Selenium but getting detected is quite common now as:将FirefoxDriver与Selenium一起使用但被检测到现在很常见,因为:
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 脚本无法检测到中找到详细讨论?
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, marionette shares much of the same API as Selenium/WebDriver , with additional commands to interact with Gecko's chrome interface.现在, marionette与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 geckodriver , selenium and firefox , you have to use the marionette by default.在使用最新版本的geckodriver 、 selenium和firefox 时,您必须默认使用牵线木偶。
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:其他问题:
Can I change the setCapabilites on/off while the driver is running?我可以在驱动程序运行时打开/关闭 setCapabilites 吗? : The short answer is No , you can't change the capabilites while the session initiated by the webdriver is In Progress
and you can find a couple of detailed discussions in: :简短的回答是否定的,当 webdriver 启动的会话In Progress
,您不能更改功能,您可以在以下位置找到一些详细的讨论:
Is it easier to do this using ChromeDriver?使用 ChromeDriver 是否更容易做到这一点? : Again the precise answer is No , ChromeDriver also gets detected and you can find a couple of detailed discussions in: :再次准确的答案是否定的, ChromeDriver也会被检测到,您可以在以下位置找到一些详细的讨论:
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.