-3

I want to get the text "We didn't recognize that email and/or password." using Selenium and Java

<div class="styles_errorDisplayInnerContainer_3R2ni-zSvPIKWfKXiviJhH">
  <span class="styles_questionMarkContainer_10mxHNOMojCyG6bxLH9qo9">
      <svg class="uni-icon uni-icon--large" viewBox="0 0 32 32" aria-labelledby="title1" role="img" fill-rule="evenodd">
        <title id="title1">IconHelp</title>
        <path fill="inherit" ></path>
      </svg>
   </span>
  <p class="uni-text" data-qa-id="error-display">We didn't recognize that email and/or password.<a class="uni-link uni-link--default uni-margin--quarter--left">Need help?</a></p>
</div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • The question should be updated to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. You need to show the code you've tried and explain the error messages received or why the code didn't work as expected. – JeffC Aug 30 '22 at 18:44

3 Answers3

0

Try the following xpaths to trace the element -

//p[contains(text(),'We didn't recognize that email and/or password')]

Or

//p[@class='uni-text'][@data-qa-id='error-display']

Also, please share the HTML markup in properly formatted manner.

indayush
  • 55
  • 2
  • 9
0

To extract the text We didn't recognize that email and/or password. from the <p> element you can use either of the following locator strategies:

  • Using cssSelector:

    System.out.println(wd.findElement(By.cssSelector("p.uni-text[data-qa-id='error-display']")).getText());
    
  • Using xpath:

    System.out.println(wd.findElement(By.xpath("//p[@class='uni-text' and @data-qa-id='error-display']")).getText());
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try as follows:

First assign the paragraph element to a WebElement object. Here using PageFactory we can assign this element to a WebElement called errorText as follows:

@FindBy(xpath = "//p[@class="uni-text" and @data-qa-id="error-display"]") WebElement errorTextLabel;

Then use the getAttribute method to get the text in the 'error-display' attribute and assign it to a String variable.

String errorText = errorTextLabel.getAttribute("error-display");