Question

I am beginner in webdriver started learning page object model

Here is the code i use:

public static class test1
{
    public static ISearchContext Driver
    {
        get
        {
            return webDriver;
        }
    }
}

public static class test2
{
    public static test3 test3
    {
        get
        {
            var Test3 = new test3();
            PageFactory.InitElements(test1.Driver, Test3 );
            return Test3 ;
        }
    }
}

public class test3
{
    public void SwitchToFrame()
    {
        test1.Driver.SwitchTo().Frame(webDriver.FindElement(By.XPath("some xpath")));

    }
}

this keeps throwing an error. SwitchTo is never given as option , Can any one tell me why , Please tell me how to get SwitchTo as option. Thanks in advance

Was it helpful?

Solution

The ISearchContext interface is not the interface that exposes SwitchTo, IWebDriver does.

What's the reason for using ISearchContext specifically? If you change it to be IWebDriver it will work.

This code, for example:

public static IWebDriver Driver
{
    get
    {
        return webDriver;
    }
}

IWebDriver implements ISearchContext, and gives much more functionality. I'd highly suggest you use that instead of just ISearchContext alone, unless you have a particular reason for doing so.

OTHER TIPS

I believe that when switching to a frame it needs to be done using the frame ID, name, or index. So, if you are trying to access an element within a frame you would have to switch to the frame first then perform webDriver.FindElement(By.XPath("some xpath")). Also, once in the frame webdriver remains in the frame until you switch back to the top level using webdriver.switchTo().defaultContent(); (Java).

I usually prefix all of my frame switches using the defaultContent:
webdriver.switchTo().defaultContent().switchTo().frame("HeaderFrame");
or
webdriver.switchTo().defaultContent().switchTo().frame("HeaderFrame").switchTo().frame("subframe");

if I need to go into a frame within a frame. This way I am always starting from the top of the page.

Hope this helps.

If you are trying to switch to a frame, Specify the frame name

driver.switchTo().Frame("YourFrameName");

If you want to switch to some frame which is in other frame first you should switch to first frame and than from there to another, for example:

public void switchToPopUpFrame(){
     switchToDefaultFrame();
     webdriver.switchTo().getPopUpFrame();
  }

and using such approach you can manipulate with frames and combine them in way you need

you are missing IWebDriver. Include IWebDriver in code and that will expose SwitchTo() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top