Careeroza
Real World Example
Long Insurance Proposal Forms
Insurance and loan application portals built by service companies often have 60+ field forms on one long page, a sticky header, and lazy sections that load while you scroll. Automation teams combine WebDriver typing with JavaScript scrolling and state checks:
JavascriptExecutor js = (JavascriptExecutor) driver;
for (Map.Entry<String, String> field : proposalData.entrySet()) { // id -> value, from test data
WebElement input = driver.findElement(By.id(field.getKey()));
js.executeScript("arguments[0].scrollIntoView({block: 'center'});", input);
input.clear();
input.sendKeys(field.getValue()); // still a real user action
}
wait.until(d -> "complete".equals(((JavascriptExecutor) d).executeScript("return document.readyState")));
driver.findElement(By.id("submit-proposal")).click();
System.out.println(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proposal-number"))).getText());Example
Output:
Run ProposalFormTest.main()Example output
Proposal No: HLI-2026-004512
Takeaway
JavaScript helps the test move around the page; WebDriver still does the typing and clicking, so the test stays honest about what a real user can do.