Gilles Cuyaubere
Gilles Cuyaubere

Reputation: 409

Selenium refuse to connect if tested application run on port other than 80

I am using selenium server. Its working well to test an application running on port 80.

but if I test an application running on another port than 80, e.g. 5001, the connection is refused.

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities;        
br = webdriver.Remote(command_executor="http://localhost:4444/wd/hub", desired_capabilities=DesiredCapabilities.CHROME)
br.get("http://127.0.0.1:5001/login/")
br.get_screenshot_as_file("/tmp/test.png")

I get the following screenshot: enter image description here

How can I test on port 5001 ?

EDIT

I am running Selenium server as a Docker container with docker-compose:

version: '2'

services:
  selenium:
    image: selenium/standalone-chrome:latest
    ports:
      - 4444:4444

Upvotes: 10

Views: 1856

Answers (1)

Jens Dibbern
Jens Dibbern

Reputation: 1454

You are running Selenium inside a Docker container. If you try to connect to localhost, that points to the Docker container itself.

You have to connect to your host like it is described here: How to access host port from docker container

Use your internal IP address or connect to the special DNS name host.docker.internal which will resolve to the internal IP address used by the host.

Upvotes: 3

Related Questions