I have a problem clicking the second button because i get this error message:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
htlm button:
<button type="button"
<span aria-hidden="true"></span>
<span > </span>
<button type="button"
<span aria-hidden="true"></span>
<span >-</span>
my code:
button = driver.find_element_by_css_selector('div.amount-control > button.btn.btn-primary.btn-fab > span.mdi.mdi-plus')
button.click()
what my code does is locating the second button, the problem is I have to locate <span aria-hidden="true"></span>
to diferenciate both buttons but i think i have to click <button type="button"
not the span because it's not interactable.
How can i click the <button>
and not the span after locating the span.
CodePudding user response:
You can receive the parent node of an element by the following.
button = driver.find_element_by_css_selector('div.amount-control > button.btn.btn-primary.btn-fab > span.mdi.mdi-plus')
actual_button = button.find_element_by_xpath('./..')
Furthermore, I would recommend you to use the following script to click an element in selenium, since selenium often has problems with clicking on elements.
try:
element = driver.find_element(By.XPATH, path)
driver.execute_script("arguments[0].click();", element)
except Exception as e:
print(e)
Note that you just have to replace the path
variable with your xpath.
CodePudding user response:
Your elements are not closed correctly. The </button>
closing tag is missing in both cases. Please change your code to this:
<button type="button"
<span aria-hidden="true"></span>
<span > </span>
</button>
<button type="button"
<span aria-hidden="true"></span>
</button>