Python 如何在Instagram上单击“跟随”按钮?

Python 如何在Instagram上单击“跟随”按钮?,python,selenium,Python,Selenium,我正在尝试使用Python Selenium单击Instagram上的follow按钮 我试过下面的代码,但不起作用 #click follow follow = driver.find_element_by_partial_link_text("Follo") ActionChains(driver).move_to_element(follow).click().perform() 您可以使用simple selenium单击元素,方法是使用xpath中的文本查找元素,然后对元素

我正在尝试使用Python Selenium单击Instagram上的follow按钮

我试过下面的代码,但不起作用

#click follow
    follow = driver.find_element_by_partial_link_text("Follo")
ActionChains(driver).move_to_element(follow).click().perform()

您可以使用simple selenium单击元素,方法是使用xpath中的文本查找元素,然后对元素使用显式等待。
你可以这样做:

follow_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//button[text()='Follow']")))
follow_button.click()
您需要添加以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

这应该对你有用。将WebElement传递给click(element)方法


尝试使用此css选择器
a.BY3EC>按钮查找元素
,然后使用
等待。元素可单击

follow = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a.BY3EC > button')))
follow.click()
以下内容:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

selenium.common.exceptions.StaleElementReferenceException:Message:stale element reference:element未附加到页面文档此解决方案对我有效我已尝试了数小时来解决此问题。。我仍然不完全理解这个过程,但谢谢!!:)
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC