[Web Automation] - How to simulate file upload?

In the previous tutorial guide you how to open multiple website and click element from this website, in this tutorial will guide you how to simulate click on file upload select path and upload file.

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


sleep(1, false);
sleep(1, false);
sleep(1, false);
}, 3000);
    • 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.

No comments:

Post a Comment