gpt4 book ai didi

java - 如何使用selenium在对话框中向下滚动

转载 作者:行者123 更新时间:2023-12-02 01:51:04 24 4
gpt4 key购买 nike

this页,该表单包含关于隐私政策部分的 2 项验证:

  1. 点击隐私政策链接,将打开一个对话框,用户应向下滚动。
  2. 选中与之相关的复选框

我在检查复选框时没有问题,但我无法在下面的窗口中向下滚动:

enter image description here

我有这个方法来等待元素加载:

public void waitForElement(String xPath) {
WebDriverWait wait = new WebDriverWait(driver, 1);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xPath)));
}

那么,我怎样才能向下滚动并关闭窗口呢?我也不知道在这种情况下应该如何使用我的 waitForElement

这里是the repo ,这是一个非常短的代码。您只需要运行feature文件

最佳答案

尝试下面的代码来向下滚动模式对话框:

// Wait for modal
WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.id("document-content")));
// Select last child of content div
WebElement element = driver.findElement(By.xpath("//div[@id='document-content']/*[last()]"));
// Scroll to last child node
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

关于java - 如何使用selenium在对话框中向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52986601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com