An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
Upload file with Selenide
In this post, we will take a look at how to upload file with Selenide. We will do that using 2 different ways -
- Upload file with visible input field
- Upload file with hidden input field
Upload file (visible input)
When the input field is visible and intractable, we can simply use the .uploadFile
command to upload the file -
// upload file$("#file-upload").uploadFile(new File("src/test/data/sample.png"));
In the code above, we are selecting the element with input[type=file]
and then doing an upload on that.
Upload file (hidden input)
When the input field is hidden and not intractable, it makes it difficult sometimes to upload file. In this case, we need to do some Javascript DOM manipulation to make the input field visible and intractable again -
// execute js codeexecuteJavaScript("document.getElementById(\"upfile_1\").classList.remove(\"file_input_hidden\")");// upload file$("#upfile_1").uploadFile(new File("src/test/data/sample.png"));
In the code above, we are first executing Javascript code to remove the class that is making the input field hidden. Once the input field is visible, we are uploading the file using the standard way.
To learn more about how to upload file in Selenide, check out the video below
Subscribe to my mailing list to get access to more content like this as well as be part of amazing free giveaways.
You can follow my content here as well -
...
I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -
Original Link: https://dev.to/automationbro/upload-file-with-selenide-1f2a
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To