find_elements_by_xpath returns empty value only on certain lines of code

  github, html, python, selenium

this is my first question so please let me know if there is anything I should change 🙂

I am trying to use Selenium Webdriver to obtain a list with all the "Unfollow" buttons in a specific GitHub ‘Followers’ tab https://github.com/toxtli?page=1&tab=followers, using the following code:

import time
import sys
from importlib import reload

reload(sys)

driver = webdriver.Firefox()
prepend = ["toxtli"]
    
for user in prepend:
    for t in range(1, 3):
        string = "https://github.com/{}?tab=followers&page={}".format(user, t)
        driver.get(string)
        time.sleep(1)

        unfollow_button = driver.find_elements_by_xpath('//*[@value="Unfollow"]')
        print(unfollow_button)

        time.sleep(1)

driver.close()

However, no matter what I try the find_elements_by_xpath function will return an empty list [], while I would expect finding several matches like the one in line 523 here: view-source:https://github.com/toxtli?page=1&tab=followers

Please note that the function seems to work fine if I try with a different line, e.g. using the code below to find the "span" in line 515:

unfollow_button = driver.find_elements_by_xpath('//*[@class="d-table-cell v-align-middle lh-condensed"]')

Why is this happening, and how can I fix it? Thank you!

Source: Python Questions

LEAVE A COMMENT