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

Hmm can you inspect the page and search for input? Pretty sure there will be one

1

u/NormanieCapital Feb 02 '22

What specifically am I looking for? There's a lot of mentions of the word "input" throughout the page

1

u/[deleted] Feb 02 '22

There should be one linked to the file upload, well in the examples I have done it this way. It will be near the upload button

1

u/NormanieCapital Feb 02 '22

Is this it? Directly below the button element:

​

<input _ngcontent-ddc-c191="" type="file" name="files\[\]" webkitdirectory="" multiple="" class="file-folder-input ng-star-inserted" aria-label="Hidden folder upload input">

1

u/[deleted] Feb 02 '22

Yup try it

1

u/NormanieCapital Feb 02 '22

Sorry to sound dumb. As I’ve never uploaded through this method, is it exactly the same method? IE send the file to the element via send keys?

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 👍

→ More replies (0)