'(Python) Selenium list objects are not callable when looping through them (autocomplete don't work either)

I'm fairly new to Python and Selenium. I'm trying to gather elements from a webpage using Python and Selenium in VS Code. I've already done similar things in other webpages so I can confirm the setups and the drivers all work fine. Here is the code which I'll try to explain line by line.

'// Creating an empty Array of Names'
Names = []

'// Finding and Saving the Table im interested in'
Table = driver.find_element_by_id("pokedex")

'// Finding and Saving in a list all the elements with a particular class name'
NameCells = Table.find_elements_by_class_name("cell-name")

'// Looping through the List'
for NameCell in NameCells:

    '// If it finds a child element with a particular class...'
    if NameCell.find_elements(By.CLASS_NAME, "text-muted"):

        '// ... append it in the array once transformed into text'
        Names.append(NameCell.find_element(By.CLASS_NAME, "text-muted").text)

    '// ... else...'
    else:

        '// ... append an element with another class into the array once transformed into text.'
        Names.append(NameCell.find_element(By.CLASS_NAME, "ent-name").text)

'// .. and print the array.'
print(Names)

The problem is that while I can use functions like "find_element" in the second and third line of code... I can't use it in the for loop, in the fifth line of code. VS Code doesn't even show me the expected functions after digiting the ".". I tried to complete it myself hoping it worked but of course it didn't.

Why does it happen?

Why can't I use WebElements functions at times?

I'm noticing it's happening mainly on Lists of objects rather than single objects.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source