這是我登錄網站的代碼:https ://drs.zalohovysystem.sk/
它一直在作業,直到我升級chromedriver.exe到版本105......現在我收到錯誤:
OpenQA.Selenium.NoSuchElementException: '沒有這樣的元素:無法找到元素:{"method":"css selector","selector":"*[name ="E-mail"]"}
private void prihlási?ToolStripMenuItem_Click(object sender, EventArgs e)
{
var driverService = ChromeDriverService.CreateDefaultService();
ChromeDriver driver = new ChromeDriver(driverService, new ChromeOptions());
const string _url = "https://drs.zalohovysystem.sk/";
const string usr = "";
const string pass = "";
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(_url);
IWebElement Login = driver.FindElement(By.Name("E-mail"));
IWebElement Password = driver.FindElement(By.Name("Password"));
IWebElement LoginButton = driver.FindElement(By.XPath("//button[.='Login']"));
Login.SendKeys(usr);
Password.SendKeys(pass);
LoginButton.Click();
using (StreamWriter sw = File.AppendText(Path.Combine(Path.GetTempPath(), "whowhen.txt")))
{
sw.WriteLine("WEB:" " " DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
}
}
uj5u.com熱心網友回復:
您使用了錯誤的定位器。
試試這個:
IWebElement Login = driver.FindElement(By.Name("email"));
IWebElement Password = driver.FindElement(By.Name("password"));
IWebElement LoginButton = driver.FindElement(By.XPath("//button[@type='submit']"));
此外,您需要添加延遲以在訪問元素之前渲染元素。
最好的方法是使用WebDriverWiats
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/512229.html
