首页 > 解决方案 > 在 selenium 中找不到/单击特定按钮(instagram bot)

问题描述

所以我一直在尝试制作一个具有多种功能的instagram bot,例如关注/登录/取消关注/垃圾邮件。我对如何实现这些功能有一些想法,但我在登录时遇到了困难。机器人写入用户名和密码,然后提交机器人成功登录,但是当“保存您的登录信息?” 页面出现我的机器人假设单击“不是现在”它给出错误(它找不到该按钮或无法单击)

我试图修复它,但无法提出任何解决方案。在过去的 5 天里,我一直在尝试解决此问题,请帮助我。

//需要的chrome驱动

源代码

def login():
        os.system("cls")
        directory= os.path.dirname(os.path.abspath(__file__))
        chromedriverdirectory = os.path.join(directory, 'chromedriver.exe')
        driver = webdriver.Chrome(executable_path = chromedriverdirectory)

        os.system("cls")
        driver.get("https://instagram.com")
        time.sleep(5)
        driver.find_element_by_xpath(("//input[@name=\"username\"]"))\
                .send_keys((username))
        os.system("cls")
        driver.find_element_by_xpath(("//input[@name=\"password\"]"))\
                .send_keys((password))
        os.system("cls")
        driver.find_element_by_xpath('//button[@type="submit"]')\
                .click()
        os.system("cls")
        time.sleep(4)

        driver.find_element_by_xpath('//button[contains(text(), "Not Now")]').click()

完整代码如下

https://pastebin.com/eXnxQSez

我的错误

标签: pythonpython-3.xseleniumselenium-webdriverselenium-chromedriver

解决方案


推荐阅读