AnilMengji
AnilMengji

Reputation: 1

"this.searchContext" is null is being returned by selenium

I am trying to integrate my framework with cucumber n testng, and harded stuff is working as expected, but I wanted to convert my harded coded to POM using Pagefactory.

public HomePage(WebDriver driver)
 { super();
 this.driver = driver; 
PageFactory.initElements(driver, this); 
 } 
private String ExpectedTitle ="Online Shopping site in India: Shop Online for Mobiles, Books, Watches, Shoes and More - Amazon.in"; 

@FindBy(xpath ="//input[@id='twotabsearchtextbox']")
public WebElement SearchField; 

public void GetTitle() {
 String ActualTitle =   driver.getTitle();
 Assert.assertEquals(ActualTitle, ExpectedTitle);    
}    
public void enterSearchCriteria (String String){
System.out.println(String);
SearchField.sendKeys(String);
}
    
public void PressEnterBtn() {
SearchField.sendKeys(Keys.ENTER);
    
}       

Unfortunately, I am getting this error..

Monitor
FAILED: Runner.TestRunner.scenario("As a customer when I search for Monitor, I want to see if the first selected item price is consistency after adding to the cart.", "Verify adding a monitor to cart on Amazon portal")
Runs Cucumber Scenarios
java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.SearchContext.findElement(org.openqa.selenium.By)" because "this.searchContext" is null

Upvotes: 0

Views: 116

Answers (0)

Related Questions