There are three ways to upload files:
(1) Check the element tag. If it is input, you can upload the file by referring to the text box input form.
Method: Same as user input, use send_keys
1 2 3 4 5 |
|
Note: If it is not an input tag, but directly a div tag, you cannot use the above method, nor can you use the (drag and drop method) drag_and_drop(value1, value2) in selenium, because the files in the folder are window operations, not browsers. The element in cannot be located. Then use the following method:
(2) Use pywinauto (can only be used on the window platform)
Steps: 1. Download the pywinauto package------pip install pywinauto
Step 2: import from pywinauto .keyboard import send_keys
Step 3: Open the window >>> Enter the file address >>> Click the Open button. Please see the specific code.
The specific code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
(3) If the computer is not a window operating system - use pyautogui cross-platform
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Finally, I would like to thank everyone who read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!
Software Testing Interview Document
We must study to find a high-paying job. The following interview questions are from the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.