-2

I am getting error :- 'str' object has no attribute 'click'

for i in range(1,100): username = driver.find_element_by_css_selector("body > div._2dDPU.CkGkG > div.zZYga > div > article > header > div.o-MQd > div.PQo_0 > div.e1e1d > span > a").text username.click()

                if username not in prev_user_list:
                    follow = driver.find_element_by_xpath("/html/body/div[5]/div[2]/div/article/header/div[2]/div[1]/div[2]/button").text
                    if follow == "Follow":
                        follow.click()
                        new_followed.append(username)
                        followed += 1
pyd3v
  • 1
  • 1

1 Answers1

2

You're saving the TEXT to the variable and then attempting a click. Try just capturing the webElement and then accessing the text such as this:

if username not in prev_user_list:
                follow = driver.find_element_by_xpath("/html/body/div[5]/div[2]/div/article/header/div[2]/div[1]/div[2]/button")
                if follow.text == "Follow":
                    follow.click()
                    new_followed.append(username)
                    followed += 1
DMart
  • 2,401
  • 1
  • 14
  • 19