2

I am writing selenium python tests on a docker image. Currently I have a server running on localhost using url http://127.0.0.1:8090/ How can I use selenium to access my localhost chrome browser. This is the code I have written, however it is not connecting my docker image to my localhost.

from selenium import webdriver
chrome_path = r"/exabgp/chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("http://127.0.0.1:8090/")
driver.find_element_by_xpath("""//{*0id="sss0"}/li/{19}/a***).click()
Max Copley
  • 430
  • 3
  • 15
  • Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – eLRuLL Sep 01 '17 at 02:04

1 Answers1

0

You can use solutions mentioned in From inside of a Docker container, how do I connect to the localhost of the machine?

Or

When you run your container use --add-host

docker run --add-host `myapp:<IPOfyourAppServer>` ....

And then in your code use

driver.get("http://myapp:8090/")

Edit-1

If you are using docker-compose, you need to use extra_hosts options

services:
  myapp:
    extra_hosts:
      - "myapp:192.168.0.10"
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265