Updating to 2.49 fails while creating driver with error as "The SearchContext of the locator object cannot be null"
This was working before, now after the upgrade fails with the below error message? "The SearchContext of the locator object cannot be null"
Fails at this line PageFactory.InitElements(TrialMaster.Browser.TMDriver, loginPage);
This works using 2.45 .net lib.
@sam22blr Please show some example code that shows the problem.
The code is from the class file where the LoginPage class has the definition. It fails in this statement "PageFactory.InitElements(TrialMaster.Browser.TMDriver, loginPage)".
public static LoginPage LoginPage
{
get
{
var loginPage = new LoginPage();
Shared.Shared.WriteLineToConsole("Switching to login frame");
PageFactory.InitElements(TrialMaster.Browser.TMDriver, loginPage);
return loginPage;
}
}
public class LoginPage { [FindsByAttribute(How = How.Name, Using = "TrialGroupName")] private IWebElement TrialGroupName; . . . }
What else has changed in your execution environment? (Hint: I'd bet the answer isn't "nothing.") The error message you're receiving indicates that the TMDriver property you're passing into the first argument of InitElements is null.
@jimevans, nothing has changed to the environment, currently we have just switched back to the 2.45 lib. Its true that that TMDriver returns null and the Driver gets initialized during the GoTo method (Pages.LoginPage.GoTo(TMURL, BrowserName);).
Then the behavior has changed. The contract for InitElements has always assumed a properly instantiated, non-null driver. The new behavior now just enforces that contract. Even if it worked before that you could pass a bill driver instance, I can assure you it was never intended to work that way.
Thanks @jimevans , i have modified the code to not return as null. But i hit another issue #1514
I have this problem a lot , you can recreate the problem in Visual Studio if you rename a page object file within the solution explorer and then try and run any tests that reference it.