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.