【发布时间】:2020-09-17 10:47:58
【问题描述】:
我正在使用 Selenium,Python 将鼠标悬停在警告图标上并获取工具提示。我用过动作链。 悬停动作第一次成功。将鼠标悬停在另一个警告图标上时,相同的代码失败。 (如果我删除第一个悬停动作,则第二个悬停动作成功,即悬停动作只执行一次)。 我得到的错误:selenium.common.exceptions.StaleElementReferenceException:消息:过时的元素引用:元素未附加到页面文档
代码sn-p:
action = ActionChains(self.driver)
Warning_icon = self.driver.find_element_by_xpath("//div/i[@class='fa fa-exclamation-circle']")
assert Warning_icon
action.move_to_element(Warning_icon) .perform()
TooltipMessage = self.driver.find_element_by_xpath("").text
action.release()
编辑1: 即使在 move_to_element(other_element) 中提到了其他元素,悬停也会发生在相同的警告消息上。 如何让鼠标悬停在新元素上? action.release() 似乎在这里不起作用。
【问题讨论】:
-
虽然不是正确的方法,但我可以将鼠标悬停在不同图标上的唯一方法是声明“动作”,每次,我都必须悬停。 actions = ActionChains(self.driver).move_to_element(IconToHover) actions.perform()
标签: python selenium hover action