Scroll Element into View with Selenium

前端 未结 30 2311
时光说笑
时光说笑 2020-11-22 08:31

Is there any way in either Selenium 1.x or 2.x to scroll the browser window so that a particular element identified by an XPath is in view of the browser? There is a focus m

30条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 09:12

    Targeting any element and sending down keys (or up/left/right) seems to work also. I know this is a bit of a hack, but I'm not really into the idea of using JavaScript to solve the scrolling problem either.

    For example:

    WebElement.sendKeys(Keys.DOWN);
    

提交回复
热议问题