0

I am working one some web tests using selenium and Nunit in C#. I am currently having some issues with Iframes. In one of my methods I would like to return to the default frame, but using driver.SwitchTo().DefaultContent(); throws a NullReferenceException somehow.

I also tried switching to frame 0 and switch to parentframe, same issue.

This is the actual method:

    public void OpenInfoTab(int timeout = 10)
    {
        while (true)
        {
            if (timeout-- < 0) throw new TimeoutException("Infotab Does not open");
            Console.WriteLine(timeout);
            element.Click(InfoTab);
            System.Threading.Thread.Sleep(100);
            try
            {
                element.SwitchTo(InfoFrame);
                element.IsDisplayed(Dip1);

                break;
            }
            catch (AssertionException)
            {
                driver.SwitchTo().DefaultContent();
            }
        }
    }

The Iframe is a window that opens when you click the infotab, it always exists, but is empty until the button has been clicked. The element.IsDisplayed(Dip1); will throw an exception if the expected element is not inside the iframe after switching. If that happens i would like to switch out of the frame and try again.

But for some reason i cant switch out again as my outer frame supposedly null.

Jaco9307
  • 13
  • 7
  • It seems the fact that its an object method is responsible. If I copy the code and just put it directly in the test instead, it works just fine. No idea how or why though – Jaco9307 Nov 15 '19 at 09:44

1 Answers1

0

Ok, I found the issue. I'm a huge idiot and never inherited the driver in the initialization of the object.

Jaco9307
  • 13
  • 7