用作按钮的 Div 标签,以及删除、报告垃圾邮件等动态按钮 [英] Div tag acting as buttons, and also Dynamic buttons like delete, report spam, etc
问题描述
这是一个练习测试用例,我必须登录到 gmail 并单击动态网络表中的所有复选框并删除邮件.所以我做了以下代码.
This is a practice test case where i have to login to gmail and click on all the checkbox in the dynamic web table and delete the mails. So i made the following code.
问题是当我检查删除按钮是否可用时.它返回 true,但是当我尝试执行删除操作时,它显示 ElementNotVisibleException
.仅供参考,我可以选择所有复选框.唯一的问题是点击由标签制成的按钮.
The problem is when i am checking the delete button is available or not. It is returning true but when i am trying to perform the delete operation it is displaying ElementNotVisibleException
. FYI i am able to select all the checkboxes. Only issue is clicking on the buttons made from tag.
//deleting mail by clicking on all checkbox
int count = 1;
List<WebElement> lst = driver.findElements(By.xpath(cbox));
System.out.println("Total number of checkboxes are : " + lst.size());
for(int i=0;i<lst.size();i++){
WebElement wwe = lst.get(i);
wwe.click();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
System.out.println("Checked on checkbox number : " + count);
count++;
}
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
try{
boolean flag = driver.findElement(By.xpath(delete)).isEnabled();
if(flag){
System.out.println("
Delete button is enabled");
}else{
System.out.println("
Delete button is not enabled");
}
driver.findElement(By.xpath(delete)).click();
}catch(Throwable t){
System.out.println("
Unable to locate delete button");
System.out.println("The exception occuring is : " + t);
}
推荐答案
我尝试了以下方法,效果很好.你只需要添加足够的等待
I've tried the following and it worked fine.You just have to add enough wait
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 60 /*timeOut in Seconds*/);
driver.get("https://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("xxx");
driver.findElement(By.id("next")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("Passwd"))).sendKeys("xxx");
driver.findElement(By.id("signIn")).click();
String cbox = "//table[@class='F cf zt']//div[@class='T-Jo-auh']";
String delete = "//div[@class='asa']/div[@class='ar9 T-I-J3 J-J5-Ji']";
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(cbox)));
int count = 1;
List<WebElement> lst = driver.findElements(By.xpath(cbox));
System.out.println("Total number of checkboxes are : " + lst.size());
for (int i = 0; i < lst.size(); i++) {
WebElement wwe = lst.get(i);
wwe.click();
System.out.println("Checked on checkbox number : " + count);
count++;
}
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(delete))).click();
try {
WebElement deleteButton = driver.findElement(By.xpath(delete));
boolean flag = deleteButton.isEnabled();
if (flag) {
System.out.println("
Delete button is enabled");
} else {
System.out.println("
Delete button is not enabled");
}
deleteButton.click();
} catch (Throwable t) {
System.out.println("
Unable to locate delete button");
System.out.println("The exception occuring is : " + t);
}
这篇关于用作按钮的 Div 标签,以及删除、报告垃圾邮件等动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!