2016-01-14 53 views
0

您好,我試圖執行,同時:元素在緩存中沒有發現 - 執行while語句

 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中有必要刷新頁面,當這個錯誤發生,但我試過上面,它不工作

任何想法?

回答

2

驅動程序正在失去edit_button。這可能是由於在while循環中執行點擊或可能會刷新。在這裏更好的方法,只需使用findelement而不是edit_button。像下面按Java(你可以使用任何定位器,我只是給使用XPath線)

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

edit_button.is_displayed():更換edit_button.is_displayed()上面一個Python編寫的。

謝謝

+0

你幫了我很多。正常工作! – RFtests