简体   繁体   English

如何使用硒在对话框中向下滚动

[英]How to scroll down in a dialog box using selenium

In this page, The form includes 2 validations regarding the Privacy Policy part: 页面中,该表格包括有关隐私政策部分的2个验证:

  1. Click on the link of Privacy Policy , it opens a dialog box and user should scroll it down. 单击“ 隐私策略”的链接,它将打开一个对话框,用户应向下滚动它。
  2. Check the checkbox related to it 选中与之相关的复选框

I have no problem in checking the checkbox, but i am not able scroll down in the below window: 我在检查复选框时没有问题, 但是无法在以下窗口中向下滚动

在此处输入图片说明

I have this method to wait till the elements get loaded: 我有这种方法,直到元素被加载:

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

So, how can i scroll down, and close the window? 那么,如何向下滚动并关闭窗口? I also don't know how should i use my waitForElement in this case? 我也不知道在这种情况下我该如何使用我的waitForElement

Here is the repo , it is a very short code. 这是仓库 ,这是一个很短的代码。 You just need to run the feature file 您只需要运行feature文件

Try below code to scroll modal dialog down: 尝试下面的代码向下滚动模式对话框:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM