Here is my code to login in into the site: https://drs.zalohovysystem.sk/
It was working until i uptaded chromedriver.exe
to version 105
... Now i get error:
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"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"));
}
}
CodePudding user response:
You are using a wrong locators.
Try this instead:
IWebElement Login = driver.FindElement(By.Name("email"));
IWebElement Password = driver.FindElement(By.Name("password"));
IWebElement LoginButton = driver.FindElement(By.XPath("//button[@type='submit']"));
Also you will need to add delays to make the elements rendered before you accessing them.
The best way to do that is to use WebDriverWiats