首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法通过登录页面

无法通过登录页面
EN

Stack Overflow用户
提问于 2018-06-17 17:32:10
回答 2查看 403关注 0票数 0

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

代码语言:javascript
复制
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”。

编辑:供参考:第三个子元素是前两个元素(用户名和密码)后面的实际"Login“按钮。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-18 02:45:31

在查看了回复并花了一些时间后,答案并不是在抓取元素、填充元素甚至提交元素时出错。问题来自于超时不起作用,而我大概是这么认为的。

我将驱动程序移到它自己的方法kill switch,这样初始调用在手动终止之前有无限的时间加载,而不是像我最初发布的代码那样自动终止。

现在我的登录问题已经解决了,我必须检查为什么超时不起作用。谢谢大家的帮助。

票数 0
EN

Stack Overflow用户

发布于 2018-06-17 17:51:45

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

代码语言:javascript
复制
WebElement parent = driver.findElement(By.id("login_form"));
// fill the fields here
parent.submit();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50895379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档