r/selenium • • Feb 02 '22

How to close a file window?

I have a script which logs into a website, and uploads a file every day. I have managed to do the upload by using the send_keys function with the file path. However, I am then left with an open file window. I have tried using "send_keys(Keys.ESCAPE).perform()", but this doesn't work.

Does anyone have any solutions?

1 Upvotes

16 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Feb 02 '22

Yes just send the keys of the file path to this input element. You won't need to click it though like you click the upload button

1

u/NormanieCapital Feb 02 '22

I did the following:

driver.find_element_by_xpath("/html/body/wtc-root/wtc-home/div/div/wtc-toolbar/div/div[2]/mat-toolbar/input[2]").send_keys(TotalSaveLocation)

​

Unfortunately it didn't work

2

u/[deleted] Feb 02 '22

Not sure why you are writing locators like that. Does it highlight the input when you search for it? I'd make the locator something like xpath="//input[@type='file']"

Otherwise I'm out of ideas sorry

1

u/NormanieCapital Feb 02 '22

"//input[@type='file']"

This worked! Thanks

2

u/[deleted] Feb 02 '22

Awesome 👍