0

I'm trying to read the text from a label that changes according to certain conditions (eg. if you enter a Username already in use, the label will display "Username already in use").

I've been trying to read in the text from the label that gets displayed, but nothing I've tried has worked so far.

The HTML looks like this:

 <div class="margin-top-10">
     <span ng-show="sentValidation">
         <span id="test1" ng-show="userNameAvailable" class="txt-color-green">
             <i class="fa fa-check fa-lg"></i>Username available
         </span>
         <span id="test2" ng-show="!userNameAvailable && userNameAvailable != null" class="txt-color-red">
                <i class="fa fa-exclamation-circle"></i>Username unavailable
          </span>
     </span>
     <div class="txt-color-red" ng-show="form.cUsername.$dirty && form.cUsername.$invalid">
          <p id="test3" ng-show="form.cUsername.$error.required">
              <i class="fa fa-exclamation-circle"></i>Username is required
          </p>
          <p id="test4" class="txt-color-red" ng-show="form.cUsername.$error.maxlength">
             <i class="fa fa-exclamation-circle"></i>Maxmium length is 50 characters
          </p>
          <p id="test5" class="txt-color-red" ng-show="form.cUsername.$error.minlength">
               <i class="fa fa-exclamation-circle"></i>Minimum length is 4 characters
           </p>
     </div>
</div>

Does anyone know how I can read what gets displayed on the screen?

3 Answers 3

1
content = driver.find_element_by_class_name('fa-exclamation-circle')
print (content.text)
Sign up to request clarification or add additional context in comments.

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
0

I didn't manage to find a way to read the text, but I found another solution. Instead of checking what text is displayed on the screen, I check to see which of the labels is being displayed (I'm able to do this because each of the labels is given a unique ID.

So the code will look something like:

Name=driver.find_element_by_id('test2')
if Name.is_displayed():
  print ("Element found")
else:
  print ("Element not found")

Comments

0
content = driver.find_element_by_class_name('fa-exclamation-circle')
content.is_displayed()

You can use the find_element_by_class_name built in method.

You need to pass the class name as a parameter.

1 Comment

Thanks, but the problem I'm having isn't with identifying the element, it's identifying which one is displayed on the screen. I need to know if "Username available" is being displayed, or if "Minimum length is 4 characters" is being displayed (or one of the others).

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.