1

I have an element that is out of view when I am using Selenium within an iFrame. I have switched the context using

Driver.SwitchTo.Frame("frame_id")

and I am able to interact with elements that are visible in the iFrame. However when I need to interact with elements that are inside the frame but out of view I cannot find a way to force the Frame to scroll down.

I have tried running some javascript: Scrolling and iframe with Javascript

Also tried using the technique described in the following article

I have tried tabbing on the last visible element to force the frame to scroll down, which works in some cases but I need a more concrete solution.

Any help would be greatly appreciated.

1 Answer 1

2

I managed to get around this issue by creating a static method that scrolls down the page:

public class Browser
{
    public static IWebDriver Driver { get; set; }
    public static ITargetLocator CurrentFrame { get; private set; }

    public static void SwitchFrame(string frameId)
    {
        CurrentFrame = Driver.SwitchTo();
        CurrentFrame.Frame(frameId);
    }

    public static void ScrollDown()
    {
        CurrentFrame.ActiveElement().SendKeys(Keys.Tab);
        CurrentFrame.ActiveElement().SendKeys(Keys.PageDown);
    }
}

Usage:

Browser.Driver = new InternetExplorerDriver();
Browser.SwitchFrame("myInnerFrame");
Browser.ScrollDown();

I just call the ScrollDown method whenever I know an element is out of view and it does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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