【问题标题】:How to scroll down within a DIV and not in the whole Page via Selenium [JAVA] [duplicate]如何通过 Selenium [JAVA] 在 DIV 中而不是在整个页面中向下滚动 [重复]
【发布时间】:2017-10-30 10:18:52
【问题描述】:

如何通过 Selenium JAVA 在 DIV 中而不是在整个页面中向下滚动

【问题讨论】:

  • This 可能会对您有所帮助。
  • @akshaygoyal 你能考虑向我们展示你的作品吗?谢谢
  • 请先努力找到问题的解决方案。仍然没有得到然后解释具体问题,并用你所做的适当描述和努力添加你的问题

标签: java selenium


【解决方案1】:

使用JavascriptExecutor

JavascriptExecutor js=(JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", element);

但是你需要探索executeScript方法下的各种条件。

或者,

如果需要移动其他元素,可以使用 Action 类,org.openqa.selenium.interactions.Actions

Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.perform();

【讨论】:

  • 此代码向下滚动到特定元素。在这里,OP 想要在一个元素内滚动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-14
  • 1970-01-01
  • 2019-05-03
  • 1970-01-01
  • 2016-08-10
  • 2012-08-30
相关资源
最近更新 更多