Using Selenium how to select two different elements that have the same ID?

0

My attempt with xPath or ID was unsuccessful.

var options = new ChromeOptions();
        options.AddArgument("--disable-gpu");

        var chromeDriver = new ChromeDriver(options);

        chromeDriver.Navigate().GoToUrl("http://radar.tntbrasil.com.br/radar/public/login");

        chromeDriver.FindElementById("login").SendKeys("");
        chromeDriver.FindElementById("senha").SendKeys("");

        chromeDriver.FindElement(By.XPath("//*[@id=\"login\"]/a")).Click();
        chromeDriver.FindElementById("login").SendKeys(Keys.Enter);

        chromeDriver.Close();

Follow the images to make it easier to understand:

    
asked by anonymous 03.10.2018 / 19:43

1 answer

1

Since the elements have the same id , although this is wrong, instead of your XPath to query all elements that have id = login, //*[@id="login"] , you can identify which type element with that id you are looking for.

//Para o input do login
chromeDriver.FindElement(By.Xpath("//input[@id=\"login\"]")).SendKeys("");

//Para o click no botão
chromeDriver.FindeElement(By.XPath("//a[@id=\"login\"]")).Click();
    
03.10.2018 / 20:37