gpt4 book ai didi

Java - 尝试使用 selenium webdriver (htmlunit) 登录网站时出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:15 25 4
gpt4 key购买 nike

我使用 Indeed.com 的实际凭据尝试了以下代码,我收到一个错误:线程“main”中出现异常 org.openqa.selenium.NoSuchElementException:无法使用//*[@id="signin_email"] 定位节点

当我使用 By.id 而不是 By.xpath 时,我收到类似的错误,知道发生了什么吗?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;


public class Testing {

public static void main(String[] args) {

WebDriver driver = new HtmlUnitDriver();

driver.get("https://secure.indeed.com/account/login?service=my&hl=en_CA&co=CA");
driver.findElement(By.xpath("//*[@id=\"signin_email\"]")).sendKeys("notworking@gmail.com");
driver.findElement(By.xpath("//*[@id=\"signin_password\"]")).sendKeys("needHelp");
driver.findElement(By.xpath("//*[@id=\"loginform\"]/button")).click();
driver.quit();

}
}

最佳答案

您需要启用java脚本,请参阅更新的代码。

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;


public class Testing {

public static void main(String[] args) {

HtmlUnitDriver driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);
driver.get("https://secure.indeed.com/account/login?service=my&hl=en_CA&co=CA");
driver.findElement(By.xpath("//*[@id=\"signin_email\"]")).sendKeys("notworking@gmail.com");
driver.findElement(By.xpath("//*[@id=\"signin_password\"]")).sendKeys("needHelp");
driver.findElement(By.xpath("//*[@id=\"loginform\"]/button")).click();
driver.quit();

}
}

关于Java - 尝试使用 selenium webdriver (htmlunit) 登录网站时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45526487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com