You can following simple step below to make this function work:
- First of all you need to navigate to the website has the file upload element in it. You can use go('url'); combine with click('xpath'); to open and click any page you want.
- After the website with the file upload available in your browser, right click on the File Upload from context menu
- You will see the code as below in the Developer Tool
- filePath: the location of the file you want to upload, it must be a absolute path, and you will need to add more "\" for it.
- For example if your file like this: "c:\photo\img.jpg" the the filePath will be "c:\\photo\\img.jpg"
- The last code is the action click on the file upload, it will use the xpath.
So when you execute this code, it will click the file upload and after 3 seconds it will send the filePath to the File Dialog and then it wait 1 second and send Tab key (3 times), and finally it will send Enter key.