您可以使用我编写的以下方法滚动到特定元素。您只需要传递 Driver 对象。// Method to scroll down to specific elementpublic static void scrollToElement(WebDriver driver) throws InterruptedException {String key = "";WebElement element = null;JavascriptExecutor js = (JavascriptExecutor) driver;element = driver.findElement(By.xpath(locator));// This will scroll the page till the element is foundjs.executeScript("arguments[0].scrollIntoView(true);", element);Thread.sleep(2000);}