12

enter image description here

I am trying to use Selenium to click the button highlighted above. I have no problem locating the element via:

download_button_path = "//button[@class='btn-primary']"
download_button = driver.find_element_by_xpath(download_button_path)

However when I try and execute:

download_button.click()

I get the error message:

ElementNotVisibleException: Message: element not interactable
  (Session info: chrome=70.0.3538.67)
  (Driver info: chromedriver=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8),platform=Mac OS X 10.11.6 x86_64)

It seems the button is not visible to selenium even though I am able to see it when performing the click manually.

I have also tried to hover over the button and then click, as well as send an Enter/Return key to the button, but nothing is working.

Any insight would be appreciated.

3
  • Are you waiting for the download_button in your code using webderiverrwait before clicking it? Commented Oct 17, 2018 at 17:05
  • Yeah, if I do that it just ends up timing out because the button never becomes available for clicking. Commented Oct 17, 2018 at 17:39
  • I think it has something to do with the ::before and ::after additions Commented Oct 17, 2018 at 18:20

3 Answers 3

10

In the HTML, I see the btn-primary is present in a bootstrap modal popup. So there may another btn-primary behind the modal pop. The XPath will be finding the element which is behind the modal which is not interactable.

btn-primary class is a generic class in bootstrap that will be used in all primary buttons. Try with unique locator with reference to modal element as a parent in your locator

download_button_path = "//[@class='lmn-edititem-modal']/../[@class=''btn-primary']"
wait = WebDriverWait(driver, 10)
download_button = wait.until(EC.visibility_of_element_located((By.XPATH, download_button_path)))
download_button .click()

We can also try this with CSS selector

driver.find_elements_by_css_selector(".lmn-edititem-modal .btn-primary") 
Sign up to request clarification or add additional context in comments.

2 Comments

Yup! I accessed it via the parent node and then grabbed the functional button. Works now. Thanks a lot.
Welcome Daniel :)
5

For me, extending relative Xpath just with its parent helped.

button = driver.find_element_by_xpath("//button[@data-value='0']")
button.click()
#this did not work

button = driver.find_element_by_xpath("//section[2]/button[@data-value='0']")
button.click()
#this worked well

Comments

3

Have you tried hovering over the button and then clicking?

try the following:

button_to_click = driver.find_element_by_xpath('button_to_click's xpath')
hover = ActionChains(driver).move_to_element(button_to_click)
hover.perform()
button_to_click.click()

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.