selenium不会遍历所有凭据,而是在线程“ main” org.openqa.selenium.NoSuchElementException中给出异常:

时间:2019-07-04 03:54:29

标签: selenium-webdriver automation webdriver

当我尝试使用循环结构使网站自动化时,第一次迭代会运行,但是第二次迭代不会并给出.NoSuchElementException错误

我已经尝试过不带循环地输入凭据,仍然是同样的问题,当页面在第一次迭代后注销时,无法找到Webelements。我已经检查了它们,它们仍然相同,不是动态的

公共静态无效TestTitle()引发异常{

    WebDriverManager.edgedriver().setup();
    WebDriver driver = new EdgeDriver();

    //user credentials in array
    String credentials[][] = {{"user39", "UserUser123"}, {"storemanager77", "UserUser123"}, {"salesmanager140", "UserUser123"}};

    driver.get("http://qa2.*******.com/user/login");

    for (int i = 0; i < credentials.length; i++) {
            //enters the credential to the website by pulling from the 2d array and logins to the app
            driver.findElement(By.name("prependedInput")).sendKeys(credentials[i][0]);
            driver.findElement(By.id("prependedInput2")).sendKeys(credentials[i][1]);
            driver.findElement(By.id("_submit")).click();
            Thread.sleep(4000);
            //finds the dropdown menu and goes to the configuration
            driver.findElement(By.xpath("//*[@id=\"user-menu\"]/a")).click();
            Thread.sleep(4000);
            driver.findElement(By.linkText("My Configuration")).click();
            Thread.sleep(4000);
            driver.navigate().refresh();

            //gets the page title
            String pageTitle = driver.getTitle();
           //gets the profile name
            String profileTitle=driver.findElement(By.xpath("//a[@href='javascript: void(0);']")).getText();
            //compare page title and profile name
            if(pageTitle.contains(profileTitle)){
                System.out.println("Passed");
            } else {
                System.out.println("Failed");
            }

            Thread.sleep(2000);
            //goes to the profile and logs out from the app
            driver.findElement(By.xpath("//*[@id=\"user-menu\"]/a")).click();
            driver.findElement(By.linkText("Logout")).click();
            //clears the login credentials from previous login
            driver.findElement(By.id("prependedInput")).clear();
            driver.findElement(By.id("prependedInput2")).clear();
            Thread.sleep(2000);

    }
}

我希望我的循环有效,通过输入网站凭据而不是注销来登录网站,然后输入相同网站的下一个凭据并注销

0 个答案:

没有答案