简体   繁体   中英

Python/selenium How to interact with a fileUpload window without using Find_element?

I'm using selenium webdriver to automate some test for a page.

My page has three radio buttons. The third button when clicked pops up a file upload window.

So the user flow would be like this: Clicks on radiobutton, the window pops uo, the user select a file, then the file is uploaded and the radio button sets checked.

First I was doing this: find_element(By.ID, 'file_uploader').sendKeys(filepath)

This worked well, except that the radio button never was clicked and so it wasn't checked after the upload.

Next I tried this: find_element(By.ID, 'radio-button-id').click() #radio button is clicked and set checked

Now the fileUpload window raises and I want to write the path of the file in the file name field (the cursor is already there when the window appears)

I can't find the way to this last thing. I tried switch to the new window, sendKeys, actionChains.sendKeys, etc, nothing works.

I can not make a find_element of the file name field in the upload window.

Any suggestion? Thanks.

I also had some problems with file dialogs. No one of those approaches you suggested worked for me as well. Anyway, I realized that this kind of thing must be done outside of selenium. Reason: WebDriver does not manage dialogs, since they are domain of the operating system. The solution I've found so far is waiting for the user input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM