0

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. enter image description here

As you can see even though element is found it gives element not found as a result. What is wrong in this script?

1 Answer 1

0

I was able to resolve this issue by my self. There were two elements with same xpath. So I used findElements to locate exact element.

WebElement logUserId = driver.findElements(By.xpath("//input[@id='msisdn']")).get(1);  
1
  • I'm not sure why there were 2 elements with same id for username. When I log out and trying to log in again, the login page opens in a new tab. That may be the reason. Hope someone can answer this. Commented Jun 14, 2022 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.