Forum Discussion
Others are having the same issue too, https://stackoverflow.com/questions/51941516/drag-and-drop-does-not-work-with-headless-chromedriver using other tools.
In Chrome, press F12 to open DevTools. Navigate to Network tab, and then upload your file on your web app. Are you able to see for example the API call being made in DevTools?
- KB12 years agoChampion Level 2
Sorry I thought you were being sarcastic in the other comment haha.
But yeah that is possible I can see the POST- rraghvani2 years agoChampion Level 3
Sorry, I just assumed you knew about DOM elements and API's.
See Sending and Receiving HTTP Requests From Script Tests
Here's a small example of POST'ing a JSON message to the URL.
function httpPostRequest() { var requestBody = JSON.stringify({ title: 'SmartBear', body: 'TestComplete', userId: 1, }); var aqHttpRequest = aqHttp.CreatePostRequest("https://jsonplaceholder.typicode.com/posts"); aqHttpRequest.SetHeader("Content-Type", "application/json"); aqHttpRequest.SetHeader("Accept", "application/json;charset=utf-8"); aqHttpRequest.SetHeader("Accept-Charset", "utf-8"); var aqHttpResponse = aqHttpRequest.Send(requestBody); Log.Message(aqHttpResponse.StatusCode); Log.Message(aqHttpResponse.Text); }
You can do something similar, providing your website doesn't require authentication, that is when it gets tricky. You need to construct the POST Header, you can copy the information that you see in DevTools; you then need to attach your file in binary format (I think it's Base64 see post https://community.smartbear.com/t5/TestComplete-Questions/Encrypt-Decrypt-Base64-string-in-TestComplete/td-p/235262). Hopefully, you should be able to upload your file 🤔. You might require help from your developers!
I don't have dotNET package installed in TC, so I can't provide an example.
- KB12 years agoChampion Level 2
<Is there anyway of interacting with the DOM element? Is it possible to use API call to POST a file?>
Hahaha yes I know, but the question you asked sounded like a sarcastic comment. But now I know it was a real question.
Thank you for your answer, we almost got it working we are also trying this methode:<input type="file" /> <script> // Get a reference to our file input const fileInput = document.querySelector('input[type="file"]'); // Create a new File object const myFile = new File(['Hello World!'], 'myFile.txt', { type: 'text/plain', lastModified: new Date(), }); // Now let's create a DataTransfer to get a FileList const dataTransfer = new DataTransfer(); dataTransfer.items.add(myFile); fileInput.files = dataTransfer.files; </script>
But did not really have time to test it thoroughly. might be doing that tomorrow because theres alot of work on my desk right now.
Thank you rraghvani
Related Content
- 2 years ago
- 2 years ago
- 3 years ago
Recent Discussions
- 6 hours ago
- 7 days ago
- 10 days ago