Reputation: 167
I was trying to click a popup button and my code shows the error:
"selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable".
I have searched but could not find the solution which works for me with the popup buttons.
Image for clicking show 10 rows and displaying the pop-up boxThe attached image is the desired result and 'Show 10 rows' is behind it and lightly seen.
I have this in my HTML code and need to click on the button.
<div class="table-responsive">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" id="loadsur" href="#Section" aria-expanded="true">LoadSurvey</a></li>
</ul>
<div class="container-fluid">
<div class="row">
<div class="col-md-12" style="margin-left: -10px;">
<div class="table-responsive">
<div id="myDataTable25_wrapper" class="dataTables_wrapper no-footer"><div class="dt-buttons">
<button class="dt-button buttons-csv buttons-html5" tabindex="0" aria-controls="myDataTable25">
<span>Csv</span></button>
<button class="dt-button buttons-excel buttons-html5" tabindex="0" aria-controls="myDataTable25">
<span>Excel</span></button>
<button class="dt-button buttons-collection buttons-page-length" tabindex="0" aria-controls="myDataTable25" aria-haspopup="true">
<span>Show 10 rows</span></button>
</div>
</div>
</div>
</div>
</div>
In Python I tried this:
def single_meter(i=0):
browser=webdriver.Chrome('C:\Webdrivers\chromedriver.exe')
for row in range (5,10):
browser.get('http://#link'+consumer_ID+'?reportrange=21%2F07%2F2018-25%2F08%2F2019')
Show10 = find_element_by_xpath("//button[@class='dt-button buttons-collection buttons-page-length']//span[contains(text(),'Show 10 rows')]")
Show10.click()
I expect to click this button which causes a popup button to appear.
Upvotes: 2
Views: 11527
Reputation: 167
I got a solution to this problem. The error was with the link in the xpath. I later copied and pasted from the html and the code now looks this:
Show10 = find_element_by_xpath("//*[@id='myDataTable2_wrapper']/div[1]/button[7]/span")
Show10.click()
And it works fine. Thank all for your help.
Upvotes: 3
Reputation: 5214
It might be in an iframe
.
Try first to find the iframe and switch to it.
browser = webdriver.Chrome()
browser.get("http:/link")
frame_id = 'frame'
wait = WebDriverWait(browser, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, frame_id)))
Then try clicking on the button.
Show10 = wait.until(expected_conditions.element_to_be_clickable((By.XPATH, "//button[@class='dt-button buttons-collection buttons-page-length']//span[contains(text(),'Show 10 rows')]")))
Show10.click()
Upvotes: 3
Reputation: 7563
Change the xpath
with :
//button[@class='dt-button buttons-collection buttons-page-length']//span[contains(text(),'Show 10 rows')]
Try use WebDriverWait
for make sure the element exist, and add expected_conditions
until the element clickable
.
Import this :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
Try this :
wait = WebDriverWait(singlemeter, 10)
Show10 = wait.until(expected_conditions.element_to_be_clickable((By.XPATH, "//button[@class='dt-button buttons-collection buttons-page-length']//span[contains(text(),'Show 10 rows')]")))
Show10.click()
Or use ActionChains
, import this :
from selenium.webdriver import ActionChains
Try this :
ActionChains(singlemeter).move_to_element(Show10).click(Show10).perform()
Upvotes: 1