wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.86k stars 241 forks source link

Configuration issues using RemoteDriver #675

Closed ralphgehy closed 1 year ago

ralphgehy commented 1 year ago

Hi! Thanks for this awesome library. I am able to use it locally as expected. However, when I am trying to integrate it using the remote driver, I am having issues when trying to set the 'addr' in the seleniumwire options.

Here is the issue. We have our Selenium Grid running on AWS. We have an EC2 instance for each node connecting to the Selenium Grid hub. First, I'm not sure which IP address should be passed to the 'addr' whether it is the grid node IP, the ec2 IP, etc?

If it is the node IP, the node gets assigned after the driver is already created so I'm not sure how it would be possible assign the node to the addr before the node is chosen.

I also tried to change the proxy to the node ip address after the driver is created. Changing the proxy does take effect but the browser cannot navigate to any URLs.

If you need any particular details or sample of the code, please let me know and I'll provide it.

Akash-nykaa commented 1 year ago

Do with you hub ip

       from selenium.webdriver import DesiredCapabilities
       from selenium.webdriver.chrome.options import Options
       from seleniumwire import webdriver as swdriver
        desired_cap = {'browserName': 'chrome'}
        chrome_options = Options()
        swoptions = {
            'addr': 'X.X.X.74'
        }
        driver = swdriver.Remote(command_executor='http://X.X.X.74:4444/wd/hub',
                                 desired_capabilities=desired_cap,
                                 options=chrome_options, seleniumwire_options=swoptions)
ralphgehy commented 1 year ago

Thanks for this. When I use the IP address of the hub, I'm getting this error below. For context, the hub is running on an AWS EC2 instance. Also, is there a minimum Selenium Hub version requirement in order for selenium-wire to successfully work with Selenium Hub. We are currently running Selenium Hub v.3.141.59

ServerException: Error starting proxy server: gaierror(11001, 'getaddrinfo failed')

ralphgehy commented 1 year ago

I figured this out.

Here is the issue. We have our Selenium Grid running on AWS. We have an EC2 instance for each node connecting to the Selenium Grid hub. First, I'm not sure which IP address should be passed to the 'addr' whether it is the grid node IP, the ec2 IP, etc?

The IP address or hostname should be the machine that is launching the execution of the tests. It is not the hub or the node (unless it's using the same machine to as one of them). Also, if trying to do this locally, if your IP address is not a public one through your ISP, you would need to set up your network to accept that incoming connection for the proxy.

If using AWS, you would need a public IP address in the security group, open an incoming port for the tests to return data to the proxy.

example: chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--proxy-server=ec2-3-83-190-70.compute-1.amazonaws.com:8087') chrome_options.add_argument('--ignore-certificate-errors')

options = { 'auto_config': False, 'addr': 'ec2-3-83-190-70.compute-1.amazonaws.com', 'port': 8087 }

driver = webdriver.Remote( command_executor=testgrid_url_response["url"], desired_capabilities=chrome_options.to_capabilities(), seleniumwire_options=options )