【问题标题】:Scroll a specific DIV inside a webpage using Selenium WebDriver使用 Selenium WebDriver 在网页内滚动特定的 DIV
【发布时间】:2015-06-28 04:12:30
【问题描述】:

我们如何使用 Selenium WebDriver 在网页中滚动特定的 DIV?不滚动整个网页,而是滚动网页内的特定 DIV。

对于经验:- https://groups.google.com/forum/#!forum/ibm.software.websphere.application-server

  • 需要“向下滚动内容”

试过了:-

Actions act2 = new Actions(browser);
WebElement draggablePartOfScrollbar=browser.findElement(By.className("G3J0AAD-b-F"));
act2.moveToElement(draggablePartOfScrollbar).clickAndHold().moveByOffset(0, 250).release().build().perform();

这可以工作,但不能滚动,有时会因为错误地点击某些内容而失败。

【问题讨论】:

    标签: java selenium


    【解决方案1】:

    我正在发布我用于上述问题的解决方案:

    1. 首先单击页面的可滚动窗格:

      Actions clickAction = new Actions(groupBrowser);
      WebElement scrollablePane = groupBrowser.findElement(By
              .className("G3J0AAD-b-F"));
      clickAction.moveToElement(scrollablePane).click().build().perform();
      
    2. 然后使用以下代码滚动:

      Actions scrollAction = new Actions(groupBrowser);
      scrollAction.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
      Thread.currentThread().sleep(5000);
      

    【讨论】:

      猜你喜欢
      • 2017-09-18
      • 2014-11-10
      • 2015-01-27
      • 2016-10-02
      • 2023-03-12
      • 2018-09-20
      • 2014-01-26
      • 1970-01-01
      相关资源
      最近更新 更多