Scroll Element into View with Selenium

前端 未结 30 2905
时光说笑
时光说笑 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:09

    This is a repeated solution with JavaScript, but with an added waiting for element.

    Otherwise ElementNotVisibleException may appear if some action on the element is being done.

    this.executeJavaScriptFunction("arguments[0].scrollIntoView(true);", elementToBeViewable);
    WebDriverWait wait = new WebDriverWait(getDriver(), 5);
    wait.until(ExpectedConditions.visibilityOf(elementToBeViewable));
    

提交回复
热议问题