java – 单击webelement直到隐藏

我有一个Web应用程序,我按下提交按钮,直到桌面上的数据可用.当我没有数据可用时,然后提交按钮隐藏.所以我们可以得到逻辑,直到提交按钮隐藏我们将点击.当按钮,不可用我们显示成功消息并加载下一个浏览器Url.

for (k=0;k>30;k++) {
    try {
       driver.findElement(By.xpath(".//*[@id='content']/input")).click();
       driver.switchTo().alert();
       driver.switchTo().alert().accept();
       Thread.sleep(20000);
    } catch (org.openqa.selenium.NoSuchElementException e){
       System.out.println(""+location+"  Done");
    }
}

这里driver.findElement(By.xpath(“.//* [@ id =’content’] / input”)).click();这一行点击我的提交按钮.提交一个浏览器警报后显示这就是为什么我接受这个.在这个循环中(k = 0; k> 30; k)盲目地我取30 ..是否有任何逻辑或任何建议如何管理这个……
《java – 单击webelement直到隐藏》

最佳答案 只需使用isDisplayed()检查是否显示元素

WebElement ele=driver.findElement(By.xpath(".//*[@id='content']/input"));
//check element is present or not
try {
if(ele.size()>0){
   if(ele.isDisplayed()){
   ele.click();
   }
   }
   //switch to alert and perform operation 
   driver.switchTo().alert();
   driver.switchTo().alert().accept();
   Thread.sleep(20000);
} 
 catch (Exception e){
   System.out.println(""+location+"  Done");
}
点赞