简体   繁体   中英

Java Selenium WebDriver Can't find form field

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

here is my selenium code

  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="">

explicit wait attempt code:

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

in HTML u shared there is no name tag. so try by.linktext("Manager")

Please check the time specified in the wait is sufficient for the element to load completely.
OR
Use different locators like cssSelector if name, id(if present) is not working.

CssSelector example
driver.findElement(By.cssSelector(input[name='name']));

For accessing the form field, use

driver.findElement(By.xpath("//input[@name='name']"));

如果在隐式/显式等待后仍面临访问元素的问题,请尝试在访问元素之前放置屏幕快照,以查看页面上是否存在该元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM