I am trying to verify a functionality as a guest user and logged in user. In order to do that I log out form the system and verify the guest user actions then login again and verify logged in user actions. I am using login page object to login again to the system reusing login page script. I'm getting this.searchContext is null error when trying to pass the user name. Even though username input web element is found, value is not passed to input field.
Below is page class script for passing username
public PayBillsPage loginAgain() {
WebElement logUserId = driver.findElement(By.xpath("//input[@id='msisdn']"));
String email = prop.getProperty("username");
JavascriptExecutor js = (JavascriptExecutor) driver;
if(logUserId.isDisplayed()) {
try {
Thread.sleep(8000);
System.out.println("Waiting time 8s");
} catch (InterruptedException e) {
e.printStackTrace();
}
//logUserId.sendKeys(email);
js.executeScript(email, logUserId);
}else {
System.out.println("input not found");
}
return new PayBillsPage();
}
I tried to pass value using javascript as well. Added a wait time before passing value. Below is the image of the console after running script.
As you can see even though element is found it gives element not found as a result. What is wrong in this script?