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

前端 未结 10 1201
走了就别回头了
走了就别回头了 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 10:53

    Instead of move the scrollbar to the button position, which sometimes it didn't work for me, I send the enter key to the button

    var element = driver.FindElement(By.Id("button"));
    element.SendKeys(Keys.Enter);
    
    0 讨论(0)
  • 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();
    }
    
    0 讨论(0)
  • 2020-11-28 11:08

    I used the method below to solve a similar issue for Selenium Java:

    public static void scrollToElementByElement(WebElement element) {
    
        Coordinates coordinates = ((Locatable)element).getCoordinates();
        coordinates.inViewPort();
        coordinates.click(); //if needed
    
    }
    

    Then called on the method on my main test class

    0 讨论(0)
  • 2020-11-28 11:09

    This works for me (in c#)-

    item = driver.findelement(by.....);
    item.SendKeys(Keys.LeftControl);
    item.Click();
    
    0 讨论(0)
  • 2020-11-28 11:09

    Just an addition: In my case the button was overlapped by another floating button.

    Just resizing the browser window solved the problem!

    0 讨论(0)
  • 2020-11-28 11:11

    I ran into a similar problem recently when there was a list of selectable objects in a JS dialog. Sometimes selenium would not select the correct object in the list. So i found this javascript suggestion:

    WebElement target = driver.findElement(By.id("myId"));
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", target);
    Thread.sleep(500); //not sure why the sleep was needed, but it was needed or it wouldnt work :(
    target.click();
    

    That solved my issue

    0 讨论(0)
提交回复
热议问题