selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Updating to 2.49 fails while creating driver with error as "The SearchContext of the locator object cannot be null"

Open sam22blr opened this issue 10 years ago • 7 comments

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 avatar Jan 18 '16 22:01 sam22blr

@sam22blr Please show some example code that shows the problem.

smccarthy avatar Jan 19 '16 13:01 smccarthy

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; . . . }

sam22blr avatar Jan 19 '16 19:01 sam22blr

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 avatar Jan 19 '16 20:01 jimevans

@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);).

sam22blr avatar Jan 20 '16 00:01 sam22blr

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.

jimevans avatar Jan 20 '16 00:01 jimevans

Thanks @jimevans , i have modified the code to not return as null. But i hit another issue #1514

sam22blr avatar Jan 20 '16 20:01 sam22blr

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.

MartinDudeDude avatar Sep 07 '16 13:09 MartinDudeDude