简体   繁体   English

为什么 Selenium 在应该点击链接并在下一页插入输入时却在上一页插入输入?

[英]Why Selenium is inserting the inputs on the previous page when it should hit the link and insert input on the next page?

I am using Selenium with Java, when I am trying to hit "forgot password" on the page I am testing, Selenium is inserting the inputs on the previous page and then going to the next page:我正在使用 Selenium 和 Java,当我试图在我正在测试的页面上点击“忘记密码”时,Selenium 在上一页插入输入,然后转到下一页:

                driver.findElement(By.xpath("//input[@type='email']")).sendKeys("email");
        driver.findElement(By.xpath("//input[@type='password']")).sendKeys("password");
        driver.findElement(By.className("btn-primary")).click();// -> here it should take us to another page and insert below data, but it is inserting the data on the page and then executing this line and moving to the next page 
        
        System.out.println(driver.findElement(By.cssSelector("span.text-with-icon")).getText());

        driver.findElement(By.linkText("Forgot Password")).click();
        driver.findElement(By.xpath("//input[@type='email']")).sendKeys("email");

When I will use driver.get("https...") it is working fine and taking me to the next page, inserting the data in the proper orde, but I want to hit the URL with "forgot password" and insert data without giving the exact address.当我将使用 driver.get("https...") 它工作正常并带我到下一页,按正确顺序插入数据,但我想用“忘记密码”点击 URL 并插入数据没有给出确切地址。

What do you mean when you talk 'page'?当你说“页面”时,你是什么意思? If you talk about new tab you should do action on new tab after driver.findElement(By.className("btn-primary")).click();如果你谈论新标签,你应该在driver.findElement(By.className("btn-primary")).click(); . . Something like this:像这样:

    for (String winHandle : driver.getWindowHandles()) {
        driver.switchTo().window(winHandle);
    }

and then on new tab you should do next steps.然后在新选项卡上,您应该执行后续步骤。 If you mean some pop-up or alert window, you should work with driver.switchTo().alert() or something like that.如果你的意思是一些弹出窗口或警报 window,你应该使用driver.switchTo().alert()或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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