div标签充当按钮,也一样删除,报告垃圾邮件等动态按钮 [英] Div tag acting as buttons, and also Dynamic buttons like delete, report spam, etc

查看:142
本文介绍了div标签充当按钮,也一样删除,报告垃圾邮件等动态按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个实践的检验情况下,我必须登录到Gmail和在动态网页点击表格上的所有复选框并删除邮件。所以,我提出以下code。

问题是,当我检查的删除按钮是否可用。它返回true,但是当我试图执行它显示 ElementNotVisibleException 删除操作。 FYI我能够选择所有的复选框。唯一的问题是点击标签从制作的按钮。

  //点击复选框的所有邮件删除
诠释计数= 1;
清单< WebElement> LST = driver.findElements(By.xpath(CBOX));
的System.out.println(复选框总数的\\ t+ lst.size());
的for(int i = 0; I< lst.size();我++){
  WebElement WWE = lst.get(ⅰ);
  wwe.click();
  driver.manage()超时()implicitlyWait(3 TimeUnit.SECONDS)。
  的System.out.println(经过对数复选框\\ T:+计数);
  算上++;
}
driver.manage()超时()implicitlyWait(3 TimeUnit.SECONDS)。
尝试{
  布尔标志= driver.findElement(By.xpath(删除))isEnabled()。
  如果(标志){
    的System.out.println(\\ n删除按钮已启用);
  }其他{
    的System.out.println(\\ n删除按钮不会启用);
  }
  。driver.findElement(By.xpath(删除))点击();
}赶上(的Throwable t)的{
  的System.out.println(\\ n无法找到删除按钮);
  的System.out.println(唯一的例外发生的历史是\\ t+ T);
}


解决方案

我试过以下和它的工作fine.You只需要添加足够的等待

 驾驶员的webdriver =新FirefoxDriver();
    WebDriverWait等待=新WebDriverWait(驱动程序,60 / *超时(秒)* /);
    driver.get(https://www.gmail.com);
    driver.findElement(By.id(电子邮件))的SendKeys(XXX)。
    。driver.findElement(By.id(下一步))点击();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(的passwd)))的SendKeys(XXX)。
    。driver.findElement(By.id(签到))点击();
    字符串CBOX =//表[@类='F CF ZT'] // DIV [@类='T-乔AUH'];
    字符串删除=// DIV [@类='ASA'] / DIV [@类='AR9 T-I-J3 J-J5吉'];    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(CBOX)));    诠释计数= 1;
    清单< WebElement> LST = driver.findElements(By.xpath(CBOX));
    的System.out.println(复选框总数的\\ t+ lst.size());
    的for(int i = 0; I< lst.size();我++){
        WebElement WWE = lst.get(ⅰ);
        wwe.click();
        的System.out.println(经过对数复选框\\ T:+计数);
        算上++;
    }    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(删除)))点击()。
    尝试{
        WebElement deleteButton = driver.findElement(By.xpath(删除));
        布尔标志= deleteButton.isEnabled();
        如果(标志){
            的System.out.println(\\ n删除按钮已启用);
        }其他{
            的System.out.println(\\ n删除按钮不会启用);
        }
        deleteButton.click();
    }赶上(的Throwable t)的{
        的System.out.println(\\ n无法找到删除按钮);
        的System.out.println(唯一的例外发生的历史是\\ t+ T);
    }

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.

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 \t: " +    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 \t: " + count); 
  count++; 
} 
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); 
try{ 
  boolean flag = driver.findElement(By.xpath(delete)).isEnabled(); 
  if(flag){ 
    System.out.println("\nDelete button is enabled"); 
  }else{ 
    System.out.println("\nDelete button is not enabled"); 
  } 
  driver.findElement(By.xpath(delete)).click(); 
}catch(Throwable t){ 
  System.out.println("\nUnable to locate delete button"); 
  System.out.println("The exception occuring is \t: " + 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 \t: " + lst.size());
    for (int i = 0; i < lst.size(); i++) {
        WebElement wwe = lst.get(i);
        wwe.click();
        System.out.println("Checked on checkbox number \t: " + 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("\nDelete button is enabled");
        } else {
            System.out.println("\nDelete button is not enabled");
        }
        deleteButton.click();
    } catch (Throwable t) {
        System.out.println("\nUnable to locate delete button");
        System.out.println("The exception occuring is \t: " + t);
    }

这篇关于div标签充当按钮,也一样删除,报告垃圾邮件等动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆