-3

I tried the script below but it doesn't work, I can't find any HTML at the "Add friend" button. Button . Is there any way to press that button? Thank you

from selenium import webdriver
import time
driver = selenium.webdriver.Firefox()
driver.get("http://www.facebook.com")
time.sleep(5)
driver.find_elements_by_link_text("Add Friend").click()

It shows :

driver.find_elements_by_link_text("Add Friend").click()
AttributeError: 'list' object has no attribute 'click'
7
  • 1
    .find_elements_by_link_text() returns a list. Why do you expect calling .click() on it to do anything or more specifically what would you expect it to do? Commented Jan 24, 2019 at 12:28
  • 3
    what´s the use case for this? why would you automate this? Commented Jan 24, 2019 at 12:30
  • 3
    “I want to” is not an answer to the question why … This can hardly have a real-world application for anyone using Facebook and this feature like it is intended to. Commented Jan 24, 2019 at 13:31
  • 1
    exactly, why would anyone want to automate this? you add friends because you know them, for example. you cannot automate this, unless you want to do something shady or randomly add people you don´t even know. there´s no point in that. Commented Jan 24, 2019 at 16:03
  • 2
    Facebook doesn't allow you to do this. So just be aware and don't come and complain here when your account gets banned Commented Jan 24, 2019 at 19:37

1 Answer 1

1

If the xpath provided is correct, try driver.find_element_by_link_text("Add Friend").click() instead of driver.find_elements as driver.find_elements returns a list instead of a single element and that's why it is returning an error in your case.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.