Gmail登录页面 - 无法向下滚动直至结束

时间:2017-03-14 17:55:05

标签: java selenium webdriver

我正在尝试自动化gmail注册页面。我输入所有必填项目,如用户名,通行证,DOB,电子邮件等,然后点击下一步按钮,我收到一条需要向下滚动的弹出消息结束然后接受按钮将被启用。 下面是我正在使用的代码及其向下滚动但没有足够的代码,以便启用“我接受”按钮。我尝试下面的代码也是双击,但它不滚动直到结束

Actions action = new Actions(driver); action.moveToElement(driver.findElement(By.id("tos-scroll-bu‌​tton"))).doubleClick‌​().build().perform()‌​; 

这是代码//

driver.manage().window().maximize();
    driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");
    driver.findElement(By.xpath(".//*[@id='FirstName']")).sendKeys("Krishna");
    driver.findElement(By.xpath(".//*[@id='LastName']")).sendKeys("Krishna");
    driver.findElement(By.xpath(".//*[@id='GmailAddress']")).sendKeys("Krishna.Krishna1154");
    driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("04Mar1989@");
    driver.findElement(By.xpath(".//*[@id='PasswdAgain']")).sendKeys("04Mar1989@");
    //Input the month
    List<WebElement> month_dropdown = driver.findElements(By.xpath(".//*[@id='BirthMonth']/div"));
    //iterate the list and get the expected month
    Thread.sleep(3000);
    for (WebElement month_ele:month_dropdown){
    String expected_month = month_ele.getAttribute("innerHTML");
    // Break the loop if match found
    Thread.sleep(3000);
    if(expected_month.equalsIgnoreCase("August")){
        month_ele.click();
        break;
    }
    driver.findElement(By.id("BirthMonth")).click();
    driver.findElement(By.id(":3")).click();
    driver.findElement(By.xpath(".//*[@id='BirthDay']")).sendKeys("14");
    driver.findElement(By.xpath(".//*[@id='BirthYear']")).sendKeys("1988");
    driver.findElement(By.id("Gender")).click();
    driver.findElement(By.id(":e")).click();
    driver.findElement(By.xpath(".//*[@id='RecoveryPhoneNumber']")).sendKeys("XXXXXXXX");
    driver.findElement(By.xpath(".//*[@id='RecoveryEmailAddress']")).sendKeys("XXX@gmail.com");
    driver.findElement(By.id("submitbutton")).click();
    Thread.sleep(3000L);
    driver.findElement(By.xpath("//*[@id='tos-scroll-button']/div/img")).click();

1 个答案:

答案 0 :(得分:1)

尝试向下滚动,直到查看“接受”按钮:

2