I am attempting to click a delete button but Selenium does not locate it even though a save button next to it is completely intractable. The only difference is the delete button has this in the html
<input type="submit" name="action[deletecheck]" class="SPSubmitRequest disabledsubmit" formmethod="get" value="Delete">
anyone run into this issue?
The selenium error is "no such element: Unable to locate element
Python code
driver.find_element_by_xpath('//*[@class="SPSubmitRequest disabledsubmit"]').click()
2 Answers 2
May be you need apply Explicit waits
and try different xpath
.
Apply Wait like below and try:
# Imports Required
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver,30)
deletebutton = wait.until(EC.element_to_be_clickable((By.XPATH,'//*[@class="SPSubmitRequest disabledsubmit"]')))
deletebutton.click()
Try below xpaths too
//input[@value='Delete']
//input[@name='action[deletecheck]']
//input[@name='action[deletecheck]' and @value='Delete']
Note that the xpath
should highlight
the Element
in the DOM
and it should be unique (1/1)
-
Thank you! It ended up being I was not in the "active" tabDrewTheTester– DrewTheTester2021年09月29日 13:38:42 +00:00Commented Sep 29, 2021 at 13:38
Well the answer was about as simple as they come... I wasn't in the active tab.The following code fixed it instantly
driver.switch_to.window(driver.window_handles[2])
$x(your_xpath)
) to check this or use any plugin like SelectorsHub to achieve this.