Python 从Docker容器内部,如何使用selenium和webdriver访问运行在上的localhost服务器http://127.0.0.1:8090/?
我正在docker映像上编写selenium python测试。 目前,我有一台使用url在localhost上运行的服务器。如何使用selenium访问我的localhost chrome浏览器。这是我编写的代码,但是它没有将docker映像连接到本地主机Python 从Docker容器内部,如何使用selenium和webdriver访问运行在上的localhost服务器http://127.0.0.1:8090/?,python,selenium,Python,Selenium,我正在docker映像上编写selenium python测试。 目前,我有一台使用url在localhost上运行的服务器。如何使用selenium访问我的localhost chrome浏览器。这是我编写的代码,但是它没有将docker映像连接到本地主机 from selenium import webdriver chrome_path = r"/exabgp/chromedriver.exe" driver = webdriver.Chrome(chrome_path) driver.g
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()
您可以使用中提到的解决方案 或 运行容器时,请使用
--添加主机
docker run --add-host `myapp:<IPOfyourAppServer>` ....
编辑-1
如果您使用的是docker compose
,则需要使用extra\u hosts
选项
services:
myapp:
extra_hosts:
- "myapp:192.168.0.10"
可能的副本非常感谢您的解决方案。我的问题是,我的基础设施使用docker compose,因此我不确定如何链接我的docker compose以运行--添加主机myapp:
…@MaxCopley,如果这对您有效,可以接受这个答案吗?嗨,Tarun,解决方案的修复方法是在非沙盒模式下运行docker容器,并将特权模式布尔值设置为true。谢谢你的建议,塔伦。你在非沙盒模式下使用了什么?@MaxCopley你介意扩展上面的答案吗?我也有类似的问题。
services:
myapp:
extra_hosts:
- "myapp:192.168.0.10"