0

我为一个测试机器人执行了这段代码,我得到了这个错误,我不知道我必须做什么?

from instapy import InstaPy

session = InstaPy(username="<your_username>", password="<your_password>")
session.login()
session.like_by_tags(["bmw", "mercedes"], amount=5)
session.set_dont_like(["naked", "nsfw"])
session.set_do_follow(True, percentage=50)
session.set_do_comment(True, percentage=50)
session.set_comments(["Nice!", "Sweet!", "Beautiful :heart_eyes:"])
session.end()

错误:

File "c:/Users/omid/Desktop/New folder/instaPy.py", line 4, in <module>
    session.login()
  File "C:\Users\omid\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\instapy\instapy.py", line 366, in login
    if not login_user(self.browser,
  File "C:\Users\omid\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\instapy\login_util.py", line 203, in login_user
    login_elem = browser.find_element_by_xpath(
  File "C:\Users\omid\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Users\omid\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\omid\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\omid\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in 
check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//article//a[text()='Log in']"}
  (Session info: chrome=87.0.4280.66)
  (Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.18363 x86_64)
4

1 回答 1

0

您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:

  • 您正在使用chromedriver=2.44
  • chromedriver=2.44的发行说明清楚地提到了以下内容:

支持Chrome v69-71

  • 您正在使用chrome=87.0.4280.66
  • ChromeDriver v87.0的发行说明清楚地提到了以下内容:

支持Chrome 版本 87

因此ChromeDriver v2.44Chrome 浏览器 v85.0之间存在明显的不匹配


解决方案

确保这件事:

  • Selenium升级到当前发布的版本 3.141.59
  • ChromeDriver已更新到当前的ChromeDriver v87.0级别。
  • Chrome已更新到当前的Chrome 版本 87.0级别。(根据ChromeDriver v87.0 发行说明)。
  • 如果您的基本Web 客户端版本太旧,请卸载它并安装最新的 GA 和已发布版本的Web 客户端
  • 重新启动系统
  • @Test非 root用户身份执行。
  • 始终driver.quit()tearDown(){}方法内调用以优雅地关闭和销毁WebDriverWeb 客户端实例。
于 2020-11-26T21:53:11.367 回答