【问题标题】:selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: instagram bot [duplicate]selenium.common.exceptions.NoSuchElementException:消息:无法找到元素:instagram bot [重复]
【发布时间】:2020-08-15 09:51:44
【问题描述】:

我正在创建一个机器人来取消关注 Instagram 上的人。

它工作正常,但在我使用它时出现错误。

当我进入我想取消关注的用户页面时,我收到了这个错误:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:

抛出这个错误是因为我的 selenium 找不到取消关注用户的按钮。

我的代码:

try:
 self._make_driver_wait("/html/body/div[1]/section/main/div/header/section/div[1]/div[2]/div/span/span[1]/button")
 self.driver.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/div[1]/div[2]/div/span/span[1]/button").click()
 self._make_driver_wait("//button[contains(text(), 'unfollow')]")
 self.driver.find_element_by_xpath("//button[contains(text(),'unfollow')]").click()
 except :
  print("time out")

不知道为什么过了一段时间找不到元素。

我确实检查了按钮,当我单击它时,页面的 XPath 与我的代码中的相同,我可以取消关注。

Instagram 是否有某种保护措施?我是不是做错了什么?

【问题讨论】:

    标签: python selenium selenium-webdriver instagram


    【解决方案1】:

    我让它和这个一起工作:

               self.driver.find_element_by_class_name("_6VtSN").click()
    

    我用查找类替换绝对路径,它像婴儿一样工作:D

    谢谢大家

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多