【问题标题】:How to scroll in div with selenium?如何用硒滚动div?
【发布时间】:2016-11-23 18:53:18
【问题描述】:

我正在尝试滚动页面上的表格。 我读过this answer。但这对我不起作用。 This is page were table presented。如何使用 webdriver 选择它并滚动到它的底部?表中的内容是可加载的。我需要这个来计算现在表中有多少项目。也许还有一些其他的提示让它更容易?

【问题讨论】:

    标签: selenium selenium-webdriver qa


    【解决方案1】:

    您可以使用 JavaScript 滚动:

    JavascriptExecutor jsExec = (JavascriptExecutor) driver;
    jsExec.executeScript("document.querySelector('#gwt-debug-contentPanel > div:nth-child(2) > div > div:nth-child(2) > div > div:nth-child(3) > div > div > div > table > tbody > tr:nth-child(1) > td:nth-child(1) > div.GNHGC04CJJ').scrollTop = 500");
    

    但是要找出数字有一个更简单的方法:

    WebElement number = driver.findElement(By.cssSelector("#gwt-debug-contentPanel > div:nth-child(2) > div > div:nth-child(2) > div > div:nth-child(3) > div > div > div > table > tbody > tr:nth-child(1) > td:nth-child(1) > div.gwt-HTML"));
    String range = number.getText();
    

    然后将较大的数字解析为整数。

    【讨论】:

      猜你喜欢
      • 2016-10-28
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      相关资源
      最近更新 更多