Scroll Element into View with Selenium

前端 未结 30 2359
时光说笑
时光说笑 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条回答
  •  囚心锁ツ
    2020-11-22 09:02

    If you think other answers were too hacky, this one is too, but there is no JavaScript injection involved.

    When the button is off the screen, it breaks and scrolls to it, so retry it... ¯\_(ツ)_/¯

    try
    {
        element.Click();
    }
    catch {
        element.Click();
    }
    

提交回复
热议问题