Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

OpenQA.Selenium – Unable to locate element

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"]"}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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"));
    }

}

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading