searchcontext of the locator object cannot be null

1,166 views
Skip to first unread message

anita punukollu

unread,
Dec 3, 2019, 4:30:42 AM12/3/19
to seleniu...@googlegroups.com
Hi All,

I am getting this error : searchcontext of the locator object cannot be null

This happens after navigating to the next and then  clicking on Create New Link.

I have attached the screenshot for better idea.

Any suggestion to handle this error.

Regards,
Anita
error.PNG
emp.PNG
Emp page.PNG
Create New Link.PNG

Oleksiy Kyrylenko

unread,
Dec 3, 2019, 3:39:18 PM12/3/19
to Selenium Users
the issue is thrown on  BasePage. Can you include the constructor of you BasePage in screenshot. Also, it seems like you are missing PageFactory initializer such as- PageFactory.InitElements(this, new RetryingElementLocator(driver, TimeSpan.FromSeconds(20))); Additionally, I believe a page factory will be deprecated at some point for dotnet bindings so you need to switch to other approaches

anita punukollu

unread,
Dec 4, 2019, 1:23:49 AM12/4/19
to seleniu...@googlegroups.com
Hi Oleksiy,
Thank you for your response.
Please find the BasePage screenshot attached.


Regards,
Anita

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/13d29a5f-de93-4419-ad3b-d99847c30ab0%40googlegroups.com.
Basepage.PNG

Oleksiy Kyrylenko

unread,
Dec 4, 2019, 11:42:10 AM12/4/19
to Selenium Users
 PageFacotry.InitElements(driver, this) trying to initialize elements in a base page not EmployeeList page. Check this article - https://www.swtestacademy.com/page-factory-selenium-webdriver/  Overall PageFactory is deprecated so there is no future for that and I highly recommend not to use it - http://jimevansmusic.blogspot.com/2018/03/deprecating-parts-of-seleniums-net.html

anita punukollu

unread,
Dec 13, 2019, 5:14:10 AM12/13/19
to seleniu...@googlegroups.com
Hi Oleksiy,

Thank you for you help.
I am not using Pagefactory as it got deprecated.

However I am still getting error as "Object reference not set to an instance of an object".

Do I need to initialise the constructor and pass the Webdriver object.

Please advise


Regards,
Anita






On Wed, Dec 4, 2019 at 4:42 PM Oleksiy Kyrylenko <oleksiykyryle...@gmail.com> wrote:
 PageFacotry.InitElements(driver, this) trying to initialize elements in a base page not EmployeeList page. Check this article - https://www.swtestacademy.com/page-factory-selenium-webdriver/  Overall PageFactory is deprecated so there is no future for that and I highly recommend not to use it - http://jimevansmusic.blogspot.com/2018/03/deprecating-parts-of-seleniums-net.html

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
Base.PNG
error to initialize.PNG

Alex K

unread,
Dec 13, 2019, 12:47:22 PM12/13/19
to Selenium Users
the issue happens on a homePage  but you provided a screenshot of a BasePage only, so it is only my guess of what the issue is 

public class BaseTest
{
}

public class MyTestSets : BaseTest
{
[Test]
public void MyTest()
{
MyPage page  = new MyPage(driver, wati);
page.PerfromAction();
}
}

public class MyPage : BasePage
{
public MyPaget(driver, wait):base(driver, wait);
}

public class BasePage
{
private IWebDeriver driver;
private IWebDriverWait wait;

public BasePage(driver, wait)
{
driver = driver;
wait = wait;
}
}

Let me explain this code-
First you initialize your driver - it is not in this example, I assume that would be done in  a BaseTest class
Then, since MyTestSet class inherits from BaseTest it will automatically can contain your driver as a result you can pass driver and wait when you create an instance of YourPage
Since YourPage inherit from BasePage which accepts 2 arguments(driver and wait) you need to provide these 2 arguments which you can do by :base(driver, wait)
As a result you can use not driver and wait in your BasePage. if you do not provide it, you cannot use. This about this just like giving a fork to someone. If you need to it and ask me for a fork untill I give it to you, you cannot have your meal. Same here, untill your provide a driver to your class, you cannot use it in your class

Looking at your example, it think this what you are trying to do

       private static T GetPage<T>(IWebDriver driver) where T : new()
        {
            var page = Activator.CreateInstance(typeof(T), new object[] { driver });
            PageFactory.InitElements(driver, page);
            return (T)page;
        }


Hope that will help


Reply all
Reply to author
Forward
0 new messages