搜索并检查gmail selenium中结果的复选框

时间:2015-10-06 09:11:19

标签: java selenium selenium-webdriver webdriver

您好我一直在尝试检查使用selenium java在Gmail中搜索的内容的复选框。如果我不在gmail中搜索这个循环是迭代的。如果我在gmail循环中搜索某些东西不是迭代。它给出的错误元素不可见异常 请帮帮我。

这是我的代码

public class gmail {

 private WebDriver driver;

 @Before
 public void setUp() throws Exception {
  driver = new FirefoxDriver();

  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }

 @Test
 public <checkboxes> void test() throws Exception {
     driver.get("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1#identifier");
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
     WebElement email =  driver.findElement(By.xpath("//*[@id='Email']"));
     email.click();
     email.sendKeys("^&^&^$^$&$*&@gmail.com");
     WebElement next = driver.findElement(By.xpath("//*[@id='next']"));
     next.click();
     WebElement password = driver.findElement(By.xpath("//*[@id='Passwd']"));
     password.sendKeys("87837876&*&*");
     WebElement signin = driver.findElement(By.xpath("//*[@id='signIn']"));
     signin.click();
     driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);



     WebDriverWait wait = new WebDriverWait(driver, 60);
     wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[7]/div[3]/div/div[1]/div[4]/div[1]/div[1]/div[3]/div/div/div/form/fieldset[2]/div/div/div[2]/table/tbody/tr/td/table/tbody/tr/td/div/input[1]")));
     WebElement search = driver.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[1]/div[4]/div[1]/div[1]/div[3]/div/div/div/form/fieldset[2]/div/div/div[2]/table/tbody/tr/td/table/tbody/tr/td/div/input[1]"));
     search.click();
     search.sendKeys("sample");
     search.sendKeys(Keys.ENTER);
     Thread.sleep(1000);



     List<WebElement> checkBox= driver.findElements(By.xpath("//*[@role='checkbox']"));

        for(int i=1; i<=checkBox.size(); i=i+1){
            checkBox.get(i).click();
            System.out.println(checkBox);

        }
    }
 }

0 个答案:

没有答案