一尘不染

线程“ main” org.openqa.selenium.NoSuchElementException中的异常:无法找到元素:// * [@@ id ='login-email']

selenium

我不得不重新测试xpath,以前工作正常,但现在却出现了错误。

我也尝试过使用其他定位器id,例如name。但仍然出现相同的错误。

package staging;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class login {

    public static void main (String[]args){
        System.setProperty("webdriver.gecko.driver","C:\\Program Files\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();

        //opening the browser
        driver.get("https://staging.keela.co/login");

        //logging
        driver.findElement(By.xpath("//*[@id='login-email']")).sendKeys("bandanakeela@yopmail.com");
        driver.findElement(By.xpath("//*[@id='login-password']")).sendKeys("keela");
        driver.findElement(By.xpath("//*[@id='login-form']/div[3]/div/button")).click();       
 }
}

阅读 408

收藏
2020-06-26

共1个答案

一尘不染

当您访问url时,https://staging.keela.co/login有一个阻止UI的Ajax加载器,因此我们必须等待Ajax加载器完成所有WebElement的加载,并且emailand
password字段变为可见。为了实现这一目标,我们将推出ExplicitWaitWebDriverWaitExpectedConditions设置为elementToBeClickableemailfield.Here是工作代码块:

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();
2020-06-26