Search code examples
pythonandroidseleniumattributeswebdriver

AttributeError: 'str' object has no attribute 'text' error


Got the: AttributeError: 'str' object has no attribute 'text' error for the following block:

 `version = driver.find_element_by_id('com.project.PROJECT:id/version').text
  print(version)
  for i in version:
     if 'Version : 1.2.0.133' == str(i):
         print('Step 46. NAS version is displayed correctly - PASS')
     else:
          print('Step 46. NAS version is incorrect - Fail')
 time.sleep(2)
 pass`

tried as well: if 'Version : 1.2.0.133' == i.text

Still not working.

print(version) is returning the correct value: Version : 1.2.0.133

But I cannot print the if value is true: print('Step 46. NAS version is displayed correctly - PASS')

Is spamming me with the else print FAIL value

Also if I use the .text for EC waiting will return an error as well.

Thank you


Solution

  • I believe driver.find_element_by_id('com.project.PROJECT:id/version') returns a str object, which doesn't have a .text attribute. Try removing .text from the first line in your code.