1

public class LoginPage extends BasePage {

public LoginPage(WebDriver driver) {
    super(driver);
    // TODO Auto-generated constructor stub
}


private By username = By.id("userid");

private By password = By.id("Bharosa_Password_PadDataField");

private By continueButton = By.xpath("//input[@type ='submit']");

private By enterButton = By.xpath("/html/body/div[1]/div[2]/form/div/table/tbody/tr/td/map/area[5]");

private By continueButtonNxt = By.cssSelector("input[value=Continue][type=submit]");

private By verificationCodeField = By.id("Bharosa_Challenge_PadDataField");

private By enterButtonVerficationCode = By.xpath("/html/body/div[1]/div[2]/form/div/table/tbody/tr/td/map/area[5]");

private By landingPageTitle = By.xpath("//a/img[@class='logo-info']");


public WebElement getUsername() {
    return getWebElement(username);
}


public WebElement getPassword() {
    return  getWebElement(password);
}



public WebElement getContinueButtonNxt() {
    return getWebElement(continueButtonNxt);
}


public WebElement getContinuebutton() {
    return getWebElement(continueButton);
}



public WebElement getenterButtonVerficationCode() {
    return getWebElement(enterButtonVerficationCode);
}


public WebElement getVerificationCodeField() {
    return getWebElement(verificationCodeField);
}

public WebElement getEnterbutton() {
    return getWebElement(enterButton);
}

public LandingPage login(String user, String pass) 
{

    getUsername().sendKeys(user);
    if(isElementPresent(continueButton).isDisplayed()) 
    {
    getContinuebutton().click();
    }
    getPassword().sendKeys(pass);
     getEnterbutton().submit();

     if(getContinueButtonNxt().isEnabled())
     {
     getContinueButtonNxt().click();
    getVerificationCodeField().sendKeys("888888");
     getenterButtonVerficationCode().submit();
     }
     else
     isElementPresentFluentWait(landingPageTitle);
     return new LandingPage(driver);
}

}

Error org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"input[value=Continue][type=submit]"} (Session info: chrome=83.0.4103.61) For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z' System info: host: 'EHL5CG009176X', ip: '10.0.0.17', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251' Driver info: org.openqa.selenium.chrome.ChromeDriver

Srikanth
  • 63
  • 4

2 Answers2

0

Do you have to hover over for the continueButtonNxt for it to be visible ? If so click on same blank spot and then click on the button.Have you implemented some wait methods on your test base ? Also, just a quick troubleshooting, implement thread.sleep(5000) and see if that works Also, try using javascript executor and see if that works

  • The element continueButtonNxt doesn't show up every time and is part of an OTP page. Application sometimes, logs in to the home page without OTP and sometimes after entering login credentials, application navigates to OTP page where this element present. – Srikanth Jun 04 '20 at 05:25
  • so looks like you don't have to use the continueButotnNxt when the system logs in the user by itself, correct ? If so, you can write an additional check to first check if the user is logged in --example . If not provide the use case. String textAfterLogin="login"; String expectedTextAfterLogin="login";// get this using getText() using selenium if(textAfterLogin!=expectedTextAfterLogin) // login by the system ? { continueButtonNxt.Click(); if no click } } – Batistuta Chand Jun 04 '20 at 16:28
0

I think first you have to create one method/function which return you element if it is there on page else it will return null value.then following code may be help you .

    //method which return element or null 
   // return element in this is 'xyzelement'
    if(xyzelement!=null)
    {
    if(xyzelement.isDisplayed() && xyzelement.isEnabled())
    {
    //Action
    }
    }
Krunal
  • 61
  • 1
  • 10