提问人:110mat110 提问时间:11/13/2023 最后编辑:110mat110 更新时间:11/13/2023 访问量:51
docker 中的 Selenium 无法访问本地网络
Selenium in docker cannot access local network
问:
我使用 selenium docker 连接到本地网络上的网站时遇到问题。我可以在本地 PC 上用硒来做到这一点。
我在 192.168.1.132 上有自己的 DNS 服务器,我想从 localhost 上的 docker 抓取 192.168.1.1 上的网站。每当我尝试它时,c# 代码都会在驱动程序上以异常结束。导航()
向远程 WebDriver 服务器发出的 URL HTTP 请求 http://localhost:4444/wd/hub/session/7ef05b4b64ea31e8d0e377c1cb833036/url 60 秒后超时。
法典:
ChromeOptions options = new();
options.AddArgument("--ignore-ssl-errors=yes");
options.AddArgument("--ignore-certificate-errors");
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options);
try
{
driver.Navigate().GoToUrl(configuration.IpToSearch); //IpToSearch = http://192.168.1.1 (NOK) http://google.com (OK)
var login = new WebDriverWait(driver, new TimeSpan(0, 0, 30)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.ClassName("password-text")));
login.SendKeys(configuration.Password);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
driver.Quit();
}
容器设置:
docker run -d -p 4444:4444 --dns=192.168.1.132 -v /dev/shm:/dev/shm selenium/standalone-chrome
容器在 Windows 24.0.6 上的 docker desktop v11 中运行
容器日志:
2023-11-13 07:53:30 06:53:30.673 INFO [LocalNode.newSession] - Session created by the Node. Id: 7503932bc446870745db8cf625604178, Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 119.0.6045.123, chrome: {chromedriverVersion: 119.0.6045.105 (38c72552c5e..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:46267}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.17.0.2:4444/sessio..., se:cdpVersion: 119.0.6045.123, se:vnc: ws://172.17.0.2:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.17.0.2:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
2023-11-13 07:53:30 06:53:30.691 INFO [LocalDistributor.newSession] - Session created by the Distributor. Id: 7503932bc446870745db8cf625604178
2023-11-13 07:53:30 Caps: Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 119.0.6045.123, chrome: {chromedriverVersion: 119.0.6045.105 (38c72552c5e..., userDataDir: /tmp/.org.chromium.Chromium...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:46267}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.17.0.2:4444/sessio..., se:cdpVersion: 119.0.6045.123, se:vnc: ws://172.17.0.2:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.17.0.2:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
2023-11-13 07:58:33 06:58:33.421 WARN [SpanWrappedHttpHandler.execute] - Unable to execute request: java.util.concurrent.TimeoutException
2023-11-13 07:58:33 Build info: version: '4.15.0', revision: '1d14b5521b'
2023-11-13 07:58:33 System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.90.1-microsoft-standard-WSL2', java.version: '11.0.20.1'
2023-11-13 07:58:33 Driver info: driver.version: unknown
2023-11-13 07:58:33 org.openqa.selenium.TimeoutException: java.util.concurrent.TimeoutException
2023-11-13 07:58:33 Build info: version: '4.15.0', revision: '1d14b5521b'
2023-11-13 07:58:33 System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.90.1-microsoft-standard-WSL2', java.version: '11.0.20.1'
2023-11-13 07:58:33 Driver info: driver.version: unknown
2023-11-13 07:58:33 at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute0(JdkHttpClient.java:410)
感谢您的帮助
答: 暂无答案
评论