在缓存中找不到元素,正在执行状态

2024-04-18 04:00:29 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我想表演一会儿:

        while edit_button.is_displayed():
           self.click_edit_button()
           self.click_delete_trainer_button()
           alert = self.driver.switch_to_alert()
           alert.accept()
           time.sleep(5)
           self.driver.refresh()

但我总是遇到这样的错误:

StaleElementReferenceException: Message: Element not found in the cache - perhaps the page has changed since it was looked up

我读到在python中,出现此错误时有必要刷新页面,但我在上面尝试过,但没有成功

有什么想法吗?


Tags: thetoselfisdriver错误buttonalert
1条回答
网友
1楼 · 发布于 2024-04-18 04:00:29

司机正在松开编辑按钮。这可能是由于执行while循环中的单击,也可能是刷新。更好的方法是使用findelement而不是edit按钮。根据java,如下所示(您可以使用任何定位器,我只是给出了使用xpath的一行代码)

 driver.findElement(By.xpath("//path of edit button")).isDisplayed();

在编辑时输入_是否显示button.u():替换编辑_是否显示button.u()在python中具有以上一个。你知道吗

谢谢

相关问题 更多 >