现在有一个场景是需要进入到 Canvas画布中 进行单击操作,现在使用过如下方法

canvas = driver.find_element_by_xpath("//canvas[@id='#canvas']")
 
actions.move_to_element(canvas).move_by_offset(600, 270).click().release().perform()

报错如下

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
经过改写后,可以正常运行
ActionChains(driver).move_to_element(canvas).move_by_offset(85,27).pause(2).click().perform()

确还是没有搞懂为什么 action = ActionChains(),在用action 去执行别的步骤就会出错;个人理解可能是之前action 在别的界面执行过操作,把前后不同的鼠标操作当成了一个场景里的不同操作,而界面变化后,导致场景找不到,才报错提示。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
  • 2021-11-19
  • 2021-12-15
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案