0

I am trying to click a save prompt on Edge using Python. The file I am saving is an excel file, once I click to export it on Edge, a prompt at the bottom of the page gives me the option to open, save, cancel. How do I get to click save? I tried using driver.find_element_by_name("Save") but that didn't work.

Should I find the position of the button instead and then click it that way? How would I find the position of the button? I know how to find the position of the mouse using pyautogui.

EDIT

Here's a visual of what I'm trying to click

Miscrosoft Edge save bar I just want to be able to click the "Save" button. It appears at the bottom of the webpage.

EDIT

Save button picture

TylerH
  • 20,799
  • 66
  • 75
  • 101
jordan23
  • 73
  • 1
  • 12

1 Answers1

2

i assume you are able to parse the link to the file? would it be a possibility for you to use the link to file and BeautifulSoup or urllib to save the file?

here is an example for using urllib: Download Files from a Website with Python

example beautifulsoup & requests: Download files using requests and BeautifulSoup

regards,

l.

Edit:

Thank you for clarification! I tried it out myself and made it work the following way:

  1. Step: Take a Screenshot of the Button you would like to click. It has to be Pixel-Perfect. (Example: enter image description here)

  2. Step, alter your code:

     postion = pyautogui.locateCenterOnScreen('pathToScreenshot')
     pyautogui.moveTo(position[0], position[1], 2)
     pyautogui.click()
    
Leni
  • 81
  • 6
  • I probably should've mentioned I'm using sharepoint. So there is metadata on a page and what the "Export to Excel" button does is it takes that data and puts it into an excel. The "Export to Excel" button it self doesn't have a link attached to it. – jordan23 Aug 06 '18 at 18:42
  • Thanks for pointing that out! I edited my original answer with two steps, which made this work for me. – Leni Aug 07 '18 at 09:04
  • I saved the picture under document on my machine and tried saving it as a PNG file then a JPG but I got this error `TypeError: 'NoneType' object is not subscriptable` . It seems like a took a clear picture, I used snipping tool on my machine. This is what I used as my path `C:\\Users\Documents\Save button for SharePoint\Save.JPG` Then when I leave off the Save.JPG out of the path I get a permission error `PermissionError: [Errno 13] Permission denied: 'C:\\Users\\CHI86786\\Documents\\Save button for Sharepoint'` @Leni – jordan23 Aug 07 '18 at 13:35
  • you need to point the path exactly to the screenshot taken. would you mind posting the picture in your original question? also mind to replace all \ with two \\ in your path. maybe the documentation helps: https://pyautogui.readthedocs.io/en/latest/screenshot.html – Leni Aug 07 '18 at 14:01
  • ok yes I pointed it at the path and get that first error `TypeError: 'NoneType' object is not subscriptable` and yup no problem I added a picture of the save button I am using @Leni – jordan23 Aug 07 '18 at 14:41
  • I got it to work, seems like it wasn't recognizing the image right away so I wrote a while loop. – jordan23 Aug 07 '18 at 15:39
  • Awesome! Congrats! – Leni Aug 08 '18 at 04:59
  • Idk if you'd be able to help with this question but it works when Im only using one screen. I have two other screens connected to my laptop and it seems like python can't find the button. I let it run for a good 5 minutes and it seems like the code was stuck in a loop. – jordan23 Aug 08 '18 at 13:06
  • as far as my research is correct pyautogui only supports one screen at the moment. here is an answer concerning moving the mouse to a second screen: https://stackoverflow.com/questions/48647175/move-mouse-cursor-to-second-monitor-using-pyautogui and here is the discussion on the github-project: https://github.com/asweigart/pyautogui/issues/9 – Leni Aug 08 '18 at 14:22
  • i also read some people recommend using pywinauto for multiple monitors. https://github.com/pywinauto/pywinauto – Leni Aug 08 '18 at 14:26