1

This is the html code:

<div id="dcf-page-export-buttons" class="no-print" style="display: block;">
                            <a id="dcf-saveaspdf" href="#" target="_blank" class="k-button">

                                Save as PDF
                            </a>
                            <a id="dcf-saveaspng" href="#" target="_blank" class="k-button">

                                Save as Image
                            </a>
                                                  <a id="dcf-printPdf" class="k-button" href="#">

                                Print
                            </a>
                        <a id="dcf-btnClose" class="k-button" href="#">

                            Close
                        </a>
                   </div>

I want to click on the Print href but it isn't being clicked. Here is my code:

exportLink = driver.find_element_by_link_text("Export")
exportLink.click()

print = driver.find_element_by_id("dcf-printPdf")
print.click()

Before finding element by id for print, I had clicked on Export href which opened a new tab and after opening of the new tab, I'm trying to click on print but getting an error. This is the error:

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Let me know if I'm going wrong somewhere or if there is a problem in the html.


The first part of the question has been answered. This is the 2nd part:

On clicking on this Print button: enter image description here

This window gets opened. It's not a new tab per se, but just a new window. Within that window, I want to click on the Save button. Is there a way to go about doing that? This is how the view looks like:

enter image description here

And here is the html code.

<cr-button class="action-button" aria-disabled="false" role="button" tabindex="0">
    Save
  </cr-button>

Here is my code till now:

exportLink = driver.find_element_by_link_text("Export")
exportLink.click()

driver.switch_to.window(driver.window_handles[1])
driver.execute_script("document.getElementById('dcf-user-info').style.display = 'none';")

time.sleep(1)
print = driver.find_element_by_link_text("Print")
print.click()

This is the snip of the error log. I've added the snip because I'm unsure of the error.

enter image description here

Small continuation of the error:

enter image description here

3
  • Your error says KeyboardInterrupt -- for me that only happens if I CTRL-C in the terminal to end the process. This happens every time you run your code? Commented Jun 2, 2021 at 14:30
  • Hey, I've found the correct answer which I've accepted. Commented Jun 2, 2021 at 14:32
  • Just to answer your question though, yes I did Ctrl + C and then got the Keyboard Interrupt message. It doesn't matter anyway because I got the answer. Thanks! Commented Jun 2, 2021 at 14:33

2 Answers 2

1

You need to switch to new tab first then you can click on Print using that Id that you have been trying.

Switch to new windows like this :

driver.switch_to.window(driver.window_handles[1])
Sign up to request clarification or add additional context in comments.

14 Comments

Hey, I've edited my question to add the next part. Please can you look into. Thanks!
@ShridharK : Are you able to click on it ? If not what is the error now ? and why are are using this driver.execute_script("document.getElementById('dcf-user-info').style.display = 'none';") ?
I'm unable to click on it. That script is used by me to remove specific part of styling of the page, it's nothing to worry about. I'll add the error in my question.
Do you know how to switch to the window that I've shown? As I mentioned it's not a new tab as such but a window pop-up. If I'm able to switch to that, then maybe I'll be able to click on Save button
I was able to solve it using this link: codegrepper.com/code-examples/python/…
|
1

As you can see from the error, the element you trying to access is not interactable.
So, the problem is not with HTML.
I can't see the page you working on, but the problem can be that element you trying to access is out of the view.
Try this

from selenium.webdriver.common.action_chains import ActionChains

print = driver.find_element_by_id("dcf-printPdf")

ActionChains(driver).move_to_element(print).click(button).perform()

3 Comments

Hey, I've edited my question to add the next part. Please can you look into. Thanks!
I was able to solve it using this link: codegrepper.com/code-examples/python/…
Hi, if you have time, can you look at my new questions: stackoverflow.com/questions/67834185/…

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.