Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set navigator.webdriver to undefined with Selenium for Firefox (geckodriver)

I am trying to set the navigator.webdriver variable in the Firefox browser to undefined using Selenium in Python.

I have been able to successfully do this when using Chrome, but now I need to do the same thing using in Firefox. When using the Firefox webdriver, execute_cdp_cmd(...) does not exist.

Does anyone know how to do the same thing using the firefox webdriver instead of the chrome webdriver?

Please see the relevant code below.

driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
        Object.defineProperty(navigator, 'webdriver', {
            get: () => undefined
        })
    """
})
like image 201
CST Avatar asked Feb 16 '20 13:02

CST


People also ask

How do I open Firefox browser with GeckoDriver in Selenium?

Step 1: Navigate to the official Selenium website. Under third-party drivers, one will find all the drivers. Just click on the Mozilla GeckoDriver documentation as shown below. Now, it will navigate to the GeckoDriver downloads link, where one can download the suitable driver based on the OS as it is platform agnostic.

Which Firefox browser needs GeckoDriver in Selenium?

Gecko driver works with Firefox version 47 or above. It can be resolved by updating Firefox version to 47 or above.

Can a website detect when you are using Selenium with GeckoDriver?

Your question is, "Can a website detect when you are using selenium with geckodriver?" The answer is yes, Basically the way the selenium detection works, is that they test for pre-defined javascript variables which appear when running with selenium.

Do you need Firefox installed to use GeckoDriver?

Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver , which needs to be installed before the below examples can be run.

How to use Firefox with geckodriver in selenium?

After Selenium 3, testers need to initialize the script to use Firefox using GeckoDriver explicitly. Selenium uses W3C Webdriver protocol to send requests to GeckoDriver, which translates them into a protocol named Marionette. Firefox will understand the commands transmitted in the form of Marionette protocol and executes them.

Why is Firefox not working in Selenium WebDriver?

Such an exception occurs when WebDriver is unable to establish a connection with Firefox. To resolve, you can clear the browser cache. Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.

How does the WebDriver connect to the Firefox browser?

The WebDriver connects with the firefox browser using the GeckoDriver. Just like the other drivers (e.g., ChromeDriver), a local server is started by this executable, which runs your selenium tests. It works as a proxy between the local and remote end to translate calls into Marionette automation protocol.

What is Webdriver in selenium?

Where possible, WebDriver drives the browser using the browser’s built-in support for automation. Since all the driver implementations except for Internet Explorer are provided by the browser vendors themselves, they are not included in the standard Selenium distribution.


1 Answers

I have since found a solution to my problem. The code below will set "navigator.webdriver" to undefined in a Firefox browser being run by Selenium.

profile.set_preference("dom.webdriver.enabled", False)
like image 156
CST Avatar answered Oct 17 '22 02:10

CST