gpt4 book ai didi

java - 无法通过登录页面

转载 作者:行者123 更新时间:2023-12-02 11:06:50 26 4
gpt4 key购买 nike

我无法通过登录页面。我正确地抓取了输入元素,填充它们并提交,但我仍然在原始页面上。我不确定确切的问题出在哪里,我尝试过“.submit”、“.click”,并模拟了 javascript ENTER 来提交凭据。

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
//Create driver, javascript enabled
WebDriver driver = new HtmlUnitDriver(true);
driver.get("https://epicmafia.com/home");
//Get parent of login form
WebElement parent = driver.findElement(By.id("login_form"));
//Get both inputs of the login form
//First is name
//Second is password
ArrayList<WebElement> children = new ArrayList<WebElement>();
for(WebElement input : parent.findElements(By.cssSelector("input")))
children.add(input);
//Fill in name
children.get(0).sendKeys("USERNAME");
//Fill in password
children.get(1).sendKeys("PASSWORD");
//Wait for good measure
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
//Submit credentials
children.get(1).submit();
//Double check inputs are desired values
System.out.println("The username is: " + children.get(0).getAttribute("value"));
System.out.println("The password is: " + children.get(1).getAttribute("value"));
//Check if pass login page
System.out.println("End URL is: " + driver.getCurrentUrl());
driver.quit();
}

登录页面为“https://epicmafia.com/home ”,成功登录后的下一页为“https://epicmafia.com/lobby ”。

编辑:供引用:第三个子元素是前两个子元素(用户名和密码)之后的实际“登录”按钮。

最佳答案

submit()应在 <form> 上执行元素

WebElement parent = driver.findElement(By.id("login_form"));
// fill the fields here
parent.submit();

关于java - 无法通过登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50895379/

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