簡體   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?

我正在使用 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");

當我將使用 driver.get("https...") 它工作正常並帶我到下一頁,按正確順序插入數據,但我想用“忘記密碼”點擊 URL 並插入數據沒有給出確切地址。

當你說“頁面”時,你是什么意思? 如果你談論新標簽,你應該在driver.findElement(By.className("btn-primary")).click(); . 像這樣:

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

然后在新選項卡上,您應該執行后續步驟。 如果你的意思是一些彈出窗口或警報 window,你應該使用driver.switchTo().alert()或類似的東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM