Home > Enterprise >  Click a button inside <span> using Python Selenium
Click a button inside <span> using Python Selenium

Time:01-29

I am trying to click on download button. The HTML Code for the button is as below:

<a  style="padding: 0px 5px; right: auto; left: 1121px; margin: 0px; top: 0px;" hidefocus="on" unselectable="on" id="toolbarbutton-1054" tabindex="-1" data-qtip="<b>Export</b><br/>Export your report into a CSV file." componentid="toolbarbutton-1054">
<span id="toolbarbutton-1054-btnWrap" data-ref="btnWrap" role="presentation" unselectable="on" style="" >
<span id="toolbarbutton-1054-btnEl" data-ref="btnEl" role="presentation" unselectable="on" style="" >
<span id="toolbarbutton-1054-btnIconEl" data-ref="btnIconEl" role="presentation" unselectable="on"  style="">&nbsp;</span>
<span id="toolbarbutton-1054-btnInnerEl" data-ref="btnInnerEl" unselectable="on" >&nbsp;
</span>
</span>
</span>
</a>

I tried this :

driver.find_element(By.ID , "toolbarbutton-1054-btnEl").click()

Getting an error: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

When I try below command it does not give error and element is recognizable. It's just that I cannot click on it.

driver.find_element(By.ID , "toolbarbutton-1054-btnEl") 

CodePudding user response:

Hey you can use the below code

class_element= driver.find_element_by_class('x-btn toolbar-menu x-unselectable x-box-item x-toolbar-item x-btn-transparent-medium')
class_element.click()

and also you can use driver.find_element_by_xpath('xpath here')

CodePudding user response:

Actually, Span does not have a clickable feature.

Please execute the following javascript code using python selenium:

document.getElementById('toolbarbutton-1054-btnEl').click();

I don't know how to execute javascript code using python selenium but it will work.

I used it with C# Selenium.

  •  Tags:  
  • Related