线程“main”中的异常org.openqa.selenium.NoSuchElementException:无法找到element:// * [@ id ='login-email'] [英] Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='login-email']

查看:210
本文介绍了线程“main”中的异常org.openqa.selenium.NoSuchElementException:无法找到element:// * [@ id ='login-email']的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不重新测试 xpath ,以前它工作正常,但现在它给了我一个错误。

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

我尝试过不同的定位器,比如 id name 。但是仍然会得到同样的错误。

I tried with different locators as well, Like id, name. but still get the same error.

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


推荐答案

As你访问网址 https://staging.keela.co/login 有一个Ajax加载器阻止了UI,所以我们必须等待Ajax加载器完成加载所有WebElements和电子邮件密码字段变为可见。为实现这一点,我们将引入 ExplicitWait WebDriverWait ExpectedConditions 对于电子邮件字段设置为 elementToBeClickable 。这是工作代码块:

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(); 

这篇关于线程“main”中的异常org.openqa.selenium.NoSuchElementException:无法找到element:// * [@ id ='login-email']的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆