question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add resolve_ip option to remote WebDriver

See original GitHub issue

🚀 Feature Proposal

The resolve_ip param should be added to the remote WebDriver class.

class WebDriver(object):
    # ...
    def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
                 desired_capabilities=None, browser_profile=None, proxy=None,
                 keep_alive=False, file_detector=None, options=None, resolve_ip=True):
        """
        Create a new driver that will issue commands using the wire protocol.

        :Args:
         - command_executor - Either a string representing URL of the remote server or a custom
             remote_connection.RemoteConnection object. Defaults to 'http://127.0.0.1:4444/wd/hub'.
         - desired_capabilities - A dictionary of capabilities to request when
             starting the browser session. Required parameter.
         - browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object.
             Only used if Firefox is requested. Optional.
         - proxy - A selenium.webdriver.common.proxy.Proxy object. The browser session will
             be started with given proxy settings, if possible. Optional.
         - keep_alive - Whether to configure remote_connection.RemoteConnection to use
             HTTP keep-alive. Defaults to False.
         - file_detector - Pass custom file detector object during instantiation. If None,
             then default LocalFileDetector() will be used.
         - options - instance of a driver options.Options class
         - resolve_ip - specify whether the remote server hostname should be resolved to an IP
             address. Defaults to True.
        """
        # ...
        if type(self.command_executor) is bytes or isinstance(self.command_executor, str):
            self.command_executor = RemoteConnection(command_executor, keep_alive=keep_alive, resolve_ip=resolve_ip)
        # ...

Motivation

I am using the Remote Webdriver to attach to a Selenium grid cluster running on Kubernetes. Since I am using an Nginx ingress, there is an issue with the resolve IP functionality of the RemoteConnection class.

driver = webdriver.Remote(
    command_executor='http://myseleniumgrid.it/wd/hub',
    ...
)

This code throws an exception since the hostname is resolved to the default backend IP. That IP is then used as the “Host” header value. Since Nginx does not know that virtualhost, the default backend response is returned: “default backend - 404”.

Example

driver = webdriver.Remote(
    command_executor='http://myseleniumgrid.it/wd/hub',
    ...,
    resolve_ip=False
)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
isaulvcommented, May 9, 2021

The real solution is to define your own RemoteConnection class that uses the custom SNI hostname and pass that in the webdriver class browser = Webdriver(command_executor=MyCustomRemoteConnection, ...) This has been a thing for a while, I found out recently.

0reactions
github-actions[bot]commented, Sep 5, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remote WebDriver - Selenium
To run a remote WebDriver client, we first need to connect to the RemoteWebDriver. We do this by pointing the URL to the...
Read more >
RemoteWebDriver and Grid - is it possible to get the server ip?
I am using selenium 2.19 and not able to resolve, JSONParser(). Is there any add on jar that I need to add to...
Read more >
Selenium RemoteWebDriver: What Is It? How Is It Different ...
Selenium RemoteWebDriver is used to execute the browser automation suite on a remote machine. In other words, RemoteWebDriver is a class that ...
Read more >
Remote WebDriver — Splinter 0.18.1 documentation
Setting up the Remote WebDriver¶. To use Remote WebDriver, you need to have access to a Selenium remote WebDriver server. Setting up one...
Read more >
What is Selenium RemoteWebDriver - BrowserStack
Run Selenium RemoteWebDriver with help of an example · To run a remote WebDriver client, first, connect to RemoteWebDriver. · Next, add the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found