【问题标题】:How to scroll down in a dialog box using selenium如何使用硒在对话框中向下滚动
【发布时间】:2018-10-25 10:04:40
【问题描述】:

this 页面中, 该表单包括关于 隐私政策 部分的 2 个验证:

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

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

我有这个方法可以等到元素被加载:

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

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

这里是the repo,代码很短。您只需要运行feature 文件

【问题讨论】:

    标签: java selenium


    【解决方案1】:

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

    // 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 2019-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多