Alejandro Olaria
Alejandro Olaria

Reputation: 43

is there any way to change the webdriver's port?

I'd like to know if there's a way to pass the --port argument to the webdriver.

I've already tried this:

driver = webdriver.Firefox(options=options, service_args=['--marionette-port','<PORT>', '--port', '<PORT>'])

but it doesn't seem to be working when I add the --port argument. It is only working for the --marionette-port.

If you go to the terminal and type: geckodriver --help, you'll see that you have all these options:

OPTIONS:

-b, --binary Path to the Firefox binary
--log Set Gecko log level [possible values: fatal, error, warn, info, config, debug, trace]
--marionette-host Host to use to connect to Gecko (default: 127.0.0.1)
--marionette-port Port to use to connect to Gecko (default: system-allocated port)
--host Host ip to use for WebDriver server (default: 127.0.0.1)
-p, --port Port to use for WebDriver server (default: 4444)

I'm already running one instance of webdriver in another script. that's why I want to change the port. any help would be great!

Upvotes: 2

Views: 6938

Answers (1)

Nickolay
Nickolay

Reputation: 32063

The port of the WebDriver server (i.e. geckodriver --port) is controlled by the parameter passed to the Service(port=). It selects a random port by default, so two scripts running at the same time shouldn't conflict.

In the current stable version of the Python client (3.141.0, released in Nov 2018) webdriver.Firefox() (unlike the Chrome variant) doesn't allow specifying a port.

In the upcoming version (you can look up the latest version on libraries.io) it does:

#  $ pip install selenium==4.0.0b4
from selenium import webdriver

service = webdriver.firefox.service.Service('geckodriver', port=1234)
driver = webdriver.Firefox(service=service)
driver.get('https://stackoverflow.com/')

#   $ ps -ef |grep geckodr
#  501 62518 62510   0  6:22PM ttys010    0:00.02 geckodriver --port 1234

Upvotes: 2

Related Questions