10

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
  • 1
    does it work if you launch browser manually? – timbre timbre Jul 05 '18 at 16:08
  • 1
    Can you please shortly describe the web server you're trying to reach? Does it work with port 5001 manually? Have your tried https? – AutomatedOwl Jul 05 '18 at 16:10
  • The application works when I open it on Chrome. It's a Flask application running on localhost:5001. It does not work with https. – Gilles Cuyaubere Jul 05 '18 at 17:17
  • Just a suggestion: try 0.0.0.0 instead of 127.0.0.1. Also is there a way to confirm that your service is running on port 5001? When I connect with Appium server, for example, I can specify a different port than the default of 4723, but the server, of course, needs to be configured to run on the port specified. – Bill Hileman Jul 05 '18 at 17:47
  • Yes I can connect to the application through Chrome by using "http://127.0.01:5001". Selenium is running on port 4444 which is fine. – Gilles Cuyaubere Jul 06 '18 at 14:01
  • Sounds like you should open a bug report. – PowerStat Oct 05 '18 at 11:44

1 Answers1

3

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.

Jens Dibbern
  • 1,434
  • 2
  • 13
  • 20