1

I used Selenium to execute a bunch of actions within a browser (tried both Chrome and FireFox) with a Mac.

I used a Selenium function to click a button that opens an OS level dialog box where I can select and "open" a file. I know Selenium can't interact with dialog boxes, but is there a Python function that can? Tkinter seems to only be able to operate within dialog boxes that it opens and not with already open boxes.

This is a version of the code and the last Selenium function that made the dialog box open is bolded:

import webbrowser  
from from selenium import webdriver  
element = webdriver.Chrome()  
element.get('http://www.somewebsite.com')  
uploadfunction = driver.find_element_by_id('upload_file').click()  

I'm adamant to do this purely through Python (via command line) before resorting to another language.

DanGar
  • 3,018
  • 17
  • 17
user3591362
  • 11
  • 1
  • 3
  • Before I just randomly throw an answer at you I would strongly advise you to look at the html code that controls the button's function. see what the html is doing exactly aside from just opening the dialog. I ran into a similar issue a few weeks ago and found a nifty little workaround in the html. And selenium isn't completely helpless when it comes to all dialogs. alert = driver.switch_to_alert() – Amazingred May 01 '14 at 03:16
  • There was a whole load of things in there but the relevant part was: Upload File  There's a chunk of javascript associated with those ids so I need to somehow make the code accept a local file (I imagine using a path here "/User/name/documents...") as the file being uploaded. I thought interacting with the dialog would be easiest. @Amazingred – user3591362 May 01 '14 at 03:41

1 Answers1

1
import win32gui

win32gui.FindWindow(ClassName,WindowName) #should give you the control of the dialog that you want.  

plus look at the accepted answer to this question for a (albeit kind of messy) helper for dialogs.

If you're still stuck let me know.

Community
  • 1
  • 1
Amazingred
  • 1,007
  • 6
  • 14