Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='login-email']

后端 未结 4 622
情深已故
情深已故 2020-11-27 23:49

I had to re-test the xpath, Previously it was working fine, But now it gives me an error.

I tried with different locators as well, Like id

4条回答
  •  日久生厌
    2020-11-28 00:05

    As you access the url https://staging.keela.co/login there is a Ajax loader which blocks the UI, so we have to wait for the Ajax loader to complete loading the all the WebElements and the email and password field becomes visible. To achieve that we will introduce ExplicitWait i.e. WebDriverWait with ExpectedConditions set to elementToBeClickable for the email field.Here is the working code block:

    System.setProperty("webdriver.gecko.driver","C:\\Utility\\BrowserDrivers\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    driver.get("https://staging.keela.co/login");
    WebDriverWait wait = new WebDriverWait (driver, 15);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='login-email']")));
    element.sendKeys("bandanakeela@yopmail.com");
    driver.findElement(By.xpath("//input[@id='login-password']")).sendKeys("keela");
    driver.findElement(By.xpath("//button[@class='btn btn-sm btn-block btn-primary']")).click(); 
    

提交回复
热议问题