0

I have an element but ı need to go there with scroll

how can ı do ıt wıthout scrolling how can ı clıck it?

  • Why do you need to view the element to click it? Selenium works off the code behind the page, and doesn't need the element to be on the screen to work. – trashpanda Dec 7 '18 at 14:35
  • 1
    @trashpanda - if the page is one of those endless scroll designs, the targeted element won't be rendered until the user scrolls far enough. That said, there isn't enough information in this question to answer properly - perhaps Zera could add the code, the HTML the code is working with, and any errors that are occurring – Kate Paulk Dec 7 '18 at 14:42
1

If your driver is of type RemoteWebDriver you can execute Javascript directly through it. (If not, you can cast it to an IJavaScriptExecutor).

Some uses include:

    /// <summary>
    /// Scroll to the page's top using javascript
    /// </summary>
    public static void ScrollToTop()
    {
        Driver.ExecuteScript("window.scrollTo(0, 0)");
    }

    /// <summary>
    /// Scrolls to the page's bottom using javascript
    /// </summary>
    public static void ScrollToBottom()
    {
        Driver.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
    }

    /// <summary>
    /// Scrolls an element into view using javascript
    /// </summary>
    /// <param name="element"></param>
    public static void ScrollToElement(IWebElement element)
    {
        Driver.ExecuteScript("arguments[0].scrollIntoView(false)", element);
    }
| improve this answer | |
  • can ı use a script lıke that on c# ? – Zera Dec 7 '18 at 18:43
  • Yes, this is C# code. I use this myself in my tests. – FDM Dec 7 '18 at 18:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.