Java Selenium WebDriver无法找到表单字段 [英] Java Selenium WebDriver Can't find form field

查看:203
本文介绍了Java Selenium WebDriver无法找到表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个注册页面,我尝试过名字,xpath,id,类似乎没什么用。

I'm testing a registration page and I've tried name, xpath, id, class and nothing seems to work.

这里是我的硒代码

  driver.findElement(By.id("pushMenu")).click();
    Thread.sleep(2000);
    driver.findElement(By.linkText("Register")).click();
    Thread.sleep(2000);
    WebElement l = driver.findElement(By.name("name"));

这里是我试图访问的表格标签

and here is the form tag I'm trying to access

<input type="text" name="name" placeholder="">

显式等待尝试代码:

 WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.name("name")));
    driver.findElement(By.name("name")).sendKeys("Testing100");


推荐答案

如果您仍然面临访问元素的问题在隐式/显式等待之后,然后在访问元素之前尝试放置屏幕截图,并查看元素是否存在于页面上。

If you are still facing the issue of accessing the element after implicit/explicit wait, then try putting a screenshot before you access the element and see if the element is present on the page or not.

这篇关于Java Selenium WebDriver无法找到表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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