Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

776
Visualizações
no such element: Unable to locate element : {"method":"css selector","selector":"#Password"} using Selenium and C#

I wrote a simple test for login

namespace Seleniumtest.Customer
{
    [TestFixture]
    class LoginTest :TestBase
    {
        [Test]
        public void LoginWithPhoneNumber()
        {
            webDriver.Navigate().GoToUrl("https://test123.ifc.ir/login");
            webDriver.FindElement(By.Id("EmailOrPhoneNumber")).SendKeys("09108599423");
            webDriver.FindElement(By.ClassName("buttons")).Click();
            var input = webDriver.FindElement(By.Id("Password"));     
            Assert.That(input.Displayed, Is.True);
        }

    }
}

This program will click login and have login and find partial view input password but its just instert the value in username and click the submit but never find password.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The issue is that on page one you have username and clickable button, and once you click on the button it will redirect you to a new page where you can provide the password.

However, this new page is not rendered properly and that's the reason you are getting

no such element: Unable to locate element : {"method":"css selector","selector":"#Password"} 

In C#-Selenium bindings, you can use the explicit wait like below:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement input = wait.Until(e => e.FindElement(By.Id("Password")));

and now the input is a web element, you can input the password with SendKeys method.

input.SendKeys("your password");

Reference link

over 4 years ago · Santiago Trujillo Relatório

0

Once you invoke the url through get(), fillup the EmailOrPhoneNumber field and click on the Submit button it would need a little while for the Password field to be visible and interactable.


Solution

In these cases to invoke Click() on the desired element you have to induce WebDriverWait for the ElementToBeClickable and you can use either of the following locator strategies:

  • Id:

    new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.Id("Password"))).Click();
    
  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("#Password"))).Click();
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='Password']"))).Click();
    

References

You can find a couple of relevant detailed discussions in:

  • C# selenium unable to locate button through xpath
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda