元素当前不可见,因此可能无法与命令持续时间或超时交互:28毫秒

时间:2016-04-08 10:29:25

标签: java selenium-webdriver testng

我试图执行多次登录(使用TestNG),我的第一个test1被传递但是剩下的测试给出了一些错误,例如“元素当前不可见,因此可能无法与命令持续时间或超时交互:28毫秒”。请妥善解决我的问题

String baseUrl = "******************";
    WebDriver driver= new FirefoxDriver();
    @BeforeTest
    public void b_url() 
    {
        driver.get(baseUrl);
    }
    @Test(priority=1)
    public void login1() throws InterruptedException
    {    
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.findElement(By.xpath("//*[@id='w1']/li/a")).click();
        driver.findElement(By.id("LoginFormusername")).sendKeys("Boopathi");
        driver.findElement(By.id("LoginForm-password")).sendKeys("test");
        driver.findElement(By.xpath("//*[@id='login-form']/div/div/div/div/div[3]/input")).click();
        Thread.sleep(3000);
        driver.findElement(By.xpath("//*[@id='w6']/li/a")).click();
        driver.findElement(By.xpath("//*[@id='w7']/li[3]/a")).click();
        //driver.navigate().refresh();
    }

    @Test(priority=2)
    public void login2() throws InterruptedException
    {

        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.findElement(By.xpath("//*[@id='w1']/li/a")).click();
        driver.findElement(By.id("LoginForm-username")).sendKeys("john");
        driver.findElement(By.id("LoginForm-password")).sendKeys("test");
        driver.findElement(By.xpath("//*[@id='login-form']/div/div/div/div/div[3]/input")).click();
        Thread.sleep(6000);
        driver.findElement(By.xpath("//*[@id='w6']/li/a")).click();
        driver.findElement(By.xpath("//*[@id='w7']/li[3]/a")).click();
        driver.navigate().refresh();
    }

    @Test(priority=3)
    public void login3() throws InterruptedException
    {

        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.findElement(By.xpath("//*[@id='w1']/li/a")).click();
        driver.findElement(By.id("LoginForm-username")).sendKeys("Kamal");
        driver.findElement(By.id("LoginForm-password")).sendKeys("test");
        driver.findElement(By.xpath("//*[@id='loginform']/div/div/div/div/div[3]/input")).click();
        driver.navigate().refresh();
        Thread.sleep(6000);
        driver.findElement(By.xpath("//*[@id='w6']/li/a")).click();
        driver.findElement(By.xpath("//*[@id='w7']/li[3]/a")).click();

    }

    @AfterTest()
    public void logout()
    {
        driver.quit();
    }

1 个答案:

答案 0 :(得分:1)

每次导航应用程序

@BeforeMethod
public void b_url() 
{
    driver.get(baseUrl);
}

删除cookie后,在每个测试中添加刷新代码

driver.navigate().refresh();

让我知道这不起作用