【发布时间】:2020-09-26 01:26:10
【问题描述】:
我正在尝试让 Instagram 机器人在帖子被不喜欢时点赞,如果帖子已经被点赞则忽略它
我设法抓住了 div 元素并单击它,但是对于类似的检测代码,我需要 "aria-label" 或 "fill" 的属性,以便机器人指定帖子是否被喜欢,但我没有管理抓住svg 元素这样做。
这是like按钮的结构
这是我的代码:
like_button = self.driver.find_element_by_xpath(
'//*[@id="react-root"]/section/main/div/div/article/div[3]/section[1]/span[1]/button/div')
like_icon=like_button.find_element_by_xpath(
'//*[@id="react-root"]/section/main/div/div/article/div[3]/section[1]/span[1]/button/div/span/svg')
每当我运行它时都会发生错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="react-root"]/section/main/div/div/article/div[3]/section[1]/span[1]/button/div/span/svg"}
【问题讨论】:
-
svg[aria-label='Like'] 将是一个更容易使用的 xpath。
标签: python-3.x selenium xpath css-selectors webdriverwait