Scroll Element into View with Selenium

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

    If nothing works, try this before clicking:

    public void mouseHoverJScript(WebElement HoverElement) {
    
        String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
        ((JavascriptExecutor) driver).executeScript(mouseOverScript, HoverElement);
    }
    

提交回复
热议问题