我尝试使用selenium和java通过google应用程序自动注册它的注册,但我得到一些错误的控制台

blmhpbnm  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(358)

我是 selenium 自动化测试的初学者。我尝试通过google应用程序自动注册,注册后它会重定向到deshboard,但控制台中出现了一些错误。

driver.findElement(By.cssSelector("a.btn.btn-circle.btn-sm.btn-google.mr-2")).click();
                WebDriverWait wait = new WebDriverWait(driver,50);
                wait.until(ExpectedConditions.numberOfWindowsToBe(2));
                Set<String> s1 = driver.getWindowHandles();
                Iterator<String> i1 = s1.iterator();
                while(i1.hasNext())
                {
                    String next_tab = i1.next();
                    if (!parentWindow.equalsIgnoreCase(next_tab))
                    {
                    driver.switchTo().window(next_tab);
                    WebDriverWait wait2 = new WebDriverWait(driver, 20);
                    wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("netcse02@gmail.com");
                    driver.findElement(By.id("identifierNext")).click();
                    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("*******");
                    driver.findElement(By.id("passwordNext")).click();
                    wait.until(ExpectedConditions.titleContains("Unify | Dashboard"));
                    System.out.println(driver.getTitle());
                    Thread.sleep(5000);             
                    }
                }

在google应用程序中注册:

没有这样的窗口:窗口已关闭:

643ylb08

643ylb081#

这是我在自动化框架中使用的两种通用方法。

public void waitForNewWindowAndSwitchToIt(WebDriver driver) {
        String cHandle = driver.getWindowHandle();
        String newWindowHandle = null;
        Set<String> allWindowHandles = driver.getWindowHandles();
        // Wait for 20 seconds for the new window and throw exception if not found
        for (int i = 0; i < 20; i++) {
            if (allWindowHandles.size() > 1) {
                for (String allHandlers : allWindowHandles) {
                    if (!allHandlers.equals(cHandle))
                        newWindowHandle = allHandlers;
                }
                driver.switchTo().window(newWindowHandle);
                break;
            } else {

            }
        }
        if (cHandle == newWindowHandle) {
            throw new RuntimeException("Time out - No window found");
        }
    }

    public boolean closeAllOtherWindows(WebDriver driver, String openWindowHandle) {
        Set<String> allWindowHandles = driver.getWindowHandles();
        for (String currentWindowHandle : allWindowHandles) {
            if (!currentWindowHandle.equals(openWindowHandle)) {
                driver.switchTo().window(currentWindowHandle);
                driver.close();
            }
        }
        driver.switchTo().window(openWindowHandle);
        if (driver.getWindowHandles().size() == 1)
            return true;
        else
            return false;
    }

相关问题