selenium 为什么instapy找不到元素xpath

yeotifhr  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(181)

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

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)
41ik7eoe

41ik7eoe1#

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

  • 您正在使用 * chromedriver = 2.44 *
  • chromedriver=2.44的发行说明中明确提到了以下内容:

支持Chrome v69 - 71

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

支持Chrome版本87
因此,* ChromeDriver v2.44 * 和 * Chrome浏览器v85.0 * 之间存在明显的不匹配
溶液
确保:

  • 如果您的基本 * Web Client * 版本太旧,请将其卸载,然后安装 * Web Client * 的最新GA和发布版本。
  • 执行 * 系统重启 *。
  • 非root用户身份执行@Test
  • 始终在tearDown(){}方法中调用driver.quit(),以正常关闭和销毁 * WebDriver * 和 * Web Client * 示例。

相关问题