2017-03-14 54 views
-2

我正在尝试自动化gmail注册页面。一旦输入所有必需的详细信息,如用户名,传递,DOB,电子邮件等,然后单击下一步按钮,我得到了一个弹出消息,需要向下滚动直到结束,然后接受按钮将被启用。 下面是我正在使用的代码和它的滚动em下来,但没有足够的下来,使“我接受”按钮启用。我想下面的代码也双击,但它不是滚动,直到结束Gmail登录页面 - 无法向下滚动直到结束

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("[email protected]"); 
    driver.findElement(By.xpath(".//*[@id='PasswdAgain']")).sendKeys("[email protected]"); 
    //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("[email protected]"); 
    driver.findElement(By.id("submitbutton")).click(); 
    Thread.sleep(3000L); 
    driver.findElement(By.xpath("//*[@id='tos-scroll-button']/div/img")).click(); 
+2

我无法想象这不违反Google的服务条款。 – jibbs

+0

有没有理由你不使用谷歌邮件API?我不认为你可能需要测试谷歌网站。 – JeffC

回答

1

尝试向下滚动,直到接受按钮鉴于:

WebElement element =driver.findElement(by); 
     JavascriptExecutor jse =(JavascriptExecutor)driver; 
     jse.executeScript("arguments[0].scrollIntoView(true);",element); 
相关问题