以下 C# 用于打開 selenium 驅(qū)動程序并連接到具有身份驗(yàn)證的代理。chrome 警報(bào)在 driver.Navigate().GoToUrl(...) 上彈出并且無法通過。這意味著我無法處理 try{}catch{} 中的警報(bào)。如何驗(yàn)證代理?到目前為止我發(fā)現(xiàn)的最接近的是這篇文章using System;using System.Net;using System.Net.Sockets;using OpenQA.Selenium;using OpenQA.Selenium.Chrome;using OpenQA.Selenium.Support.UI;namespace ConnectProxy{ internal class Program { private static void Main() { var proxy = new { Ip = "XXX", Username = "YYY", Password = "ZZZ", Port = "80" }; string PROXY = proxy.Ip + ":" + proxy.Port; Proxy pro = new Proxy(); pro.HttpProxy = PROXY; pro.FtpProxy = PROXY; pro.SslProxy = PROXY; ChromeOptions options = new ChromeOptions(); options.Proxy = pro; IWebDriver driver = new ChromeDriver(options); driver.Navigate().GoToUrl("https://" + proxy.Username + ":" + proxy.Password + "@" + "whatismyipaddress.com/"); try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15)); wait.Until(c => c.FindElement(By.Id("content-section"))); IAlert alert = driver.SwitchTo().Alert(); alert.SetAuthenticationCredentials(proxy.Username, proxy.Password); alert.Accept(); } catch { } } }}
1 回答

catspeake
TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊
根據(jù)selenium 文檔,嘗試通過 selenium 進(jìn)行操作不是可用資源。相反,根據(jù)帖子,您需要向 chrome 添加一個(gè)擴(kuò)展,其中包含代理主機(jī)和身份驗(yàn)證詳細(xì)信息。
- 1 回答
- 0 關(guān)注
- 221 瀏覽
添加回答
舉報(bào)
0/150
提交
取消