Issues scrolling to the bottom of the Google signup terms

I’m trying to automate the signup process for Google, but I’m facing a challenge with the terms of service popup. After I fill in all the necessary information, like the username, password, and date of birth, I click the next button and a terms popup appears. I need to scroll down to the end of this popup for the Accept button to be clickable.

However, my current scrolling method is not reaching the bottom. I’ve even attempted to double-click on the scrolling element using Actions, but it still isn’t enough.

Here’s the attempt I made to scroll:

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

And this is the full code I’m using for automation:

driver.manage().window().maximize();
driver.get("https://accounts.google.com/signup");
driver.findElement(By.id("FirstName")).sendKeys("Jane");
driver.findElement(By.id("LastName")).sendKeys("Doe");
driver.findElement(By.id("GmailAddress")).sendKeys("janedoe2024");
driver.findElement(By.id("Passwd")).sendKeys("SecurePass456!");
driver.findElement(By.id("PasswdAgain")).sendKeys("SecurePass456!");
driver.findElement(By.id("BirthMonth")).click();
driver.findElement(By.xpath("//option[text()='April']")).click();
driver.findElement(By.id("BirthDay")).sendKeys("20");
driver.findElement(By.id("BirthYear")).sendKeys("1992");
driver.findElement(By.id("Gender")).click();
driver.findElement(By.xpath("//option[text()='Female']")).click();
driver.findElement(By.id("RecoveryPhoneNumber")).sendKeys("5559876543");
driver.findElement(By.id("RecoveryEmailAddress")).sendKeys("[email protected]");
driver.findElement(By.id("submitbutton")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id='terms-scroll-area']//img")).click();

What can I do to ensure that I scroll all the way down in the terms popup so that the Accept button is enabled?

I had this exact same problem automating Google signups. JavaScript executor works way better than Actions for scrolling in modal dialogs. The terms popup has weird scroll behavior - you need to scroll the container element directly to max height.

Try this instead:

WebElement scrollArea = driver.findElement(By.id("tos-scroll-area"));
JavaScriptExecutor js = (JavaScriptExecutor) driver;
js.executeScript("arguments[0].scrollTop = arguments[0].scrollHeight;", scrollArea);

This forces the scroll container to jump straight to the bottom, which enables the Accept button right away. I’ve used this on different Google signup variations and it handles the modal’s scrolling way better than mouse actions.

Honestly, just use Selenium’s sendKeys with PAGE_DOWN or END keys on the scroll container. Way simpler than JavaScript stuff. Something like driver.findElement(By.id("tos-scroll-area")).sendKeys(Keys.END); should get you to the bottom instantly. Worked for me when Actions and JS failed on similar popups.

Try explicit waits with a scrolling loop - the terms content needs to fully load before you scroll. I hit the same issue where the popup wasn’t completely rendered when I scrolled right away.

Here’s what worked for me - wait for the scroll area, then use JavaScript executor with a small delay:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement termsArea = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("tos-scroll-area")));
Thread.sleep(1000); // Allow content to load
JavaScriptExecutor js = (JavaScriptExecutor) driver;
js.executeScript("arguments[0].scrollTo(0, arguments[0].scrollHeight);", termsArea);

The key is using scrollTo instead of scrollTop and giving the popup time to render everything. Google’s terms popup sometimes loads more content as you scroll, so the initial scroll height won’t show the full document.