It's a Python question! AttributeError: 'str' object has no attribute 'text'

Asked 2 years ago, Updated 2 years ago, 104 views

Hi, everyone. An error appears when trying to turn as shown below. Is it not possible to print certain strings after append through repetitive statements?

            items = driver.find_element(By.CLASS_NAME, 'items').text
            items_split = items.split("/")
            item_list = []
            for item in items_split:
                item_list.append(item.text)
            print(item_list)
AttributeError: 'str' object has no attribute 'text'

for python loops

2022-09-20 11:27

1 Answers

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

Str object does not have a text element. This is a problem caused by trying to replace the data that has already been replaced by str with a text command with str once again.

items = driver.find_element(By.CLASS_NAME, 'items').text
items_split = items.split("/")
item_list = []
for item in items_split:
    item_list.append(item)#(item.text)
print(item_list)


2022-09-20 11:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.