Selenium webdriver can't click on a link outside the page

前端 未结 10 1260
走了就别回头了
走了就别回头了 2020-11-28 10:50

I am having an issue with Selenium WebDriver. I try to click on a link that is outside the window page (you\'d need to scroll up to see it). My current code is fairly standa

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 11:01

    This solution worked like a charm for me:

    public void click(By by) throws Exception{
        WebElement element = driver.findElement(by);
        ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
        Thread.sleep(500);
        element.click();
    }
    

提交回复
热议问题