【问题标题】:Why instapy cannot find element xpath为什么 instapy 找不到元素 xpath
【发布时间】:2021-03-09 17:31:44
【问题描述】:

我为一个测试机器人执行了这段代码,我得到了这个错误,我不知道我该怎么办?

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)

【问题讨论】:

    标签: python-3.x python-2.7 selenium selenium-chromedriver instapy


    【解决方案1】:

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

    • 您正在使用 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 升级到当前发布的Version 3.141.59
    • ChromeDriver 已更新到当前的ChromeDriver v87.0 级别。
    • Chrome 已更新到当前的 Chrome 版本 87.0 级别。 (根据ChromeDriver v87.0 release notes)。
    • 如果您的基本 Web 客户端 版本太旧,请卸载它并安装最新的 GA 和发布版本的 Web 客户端
    • 进行系统重启
    • 非root用户身份执行@Test
    • 始终在 tearDown(){} 方法中调用 driver.quit() 以优雅地关闭和销毁 WebDriverWeb Client 实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-12
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多