解決selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

話不多說,直接上方法:

原來部分的代碼爲:

username=self.wait.until(EC.presence_of_element_located((By.ID,'loginName')))
password=self.wait.until(EC.presence_of_element_located((By.ID,'loginPassword')))
submit=self.wait.until(EC.presence_of_element_located((By.ID,'loginAction')))
username.send_keys(self.username)
password.send_keys(self.password)
submit.click()

運行後報錯:selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable.

Solution:1.臨時覆蓋別的element來保證自己的element

方法是我們更換等待的條件,一種是self.wait.until(expected_conditions.invisiblity_of_element_located((By.ID,'id_of_the_element_to_be_invisiblity')))

另一種是self.wait.until(expected_conditions.element_to_be_clickable((By.ID,'id_of_the_element_to_be_clickable'))),這裏我採用了第二種的處理方法。

 submit=self.wait.until(EC.element_to_be_clickable((By.ID,'loginAction')))

2.永久覆蓋element來保證自己的element。

方法是如下的代碼:

WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);

第二種方法暫時還沒有理解好,有理解的可以交流交流。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章