xxxxxxxxxx
Public void fileUpload(Stirng path){
WebELement upload = driver.findELement; Upload.sendKeys(path)
}
• We need to locate the upload button in html.
• The element will have tag input.
• Then we do sendKeys by passing the path to file which we want to upload
xxxxxxxxxx
const formData = new FormData();
const fileField = document.querySelector('input[type="file"]');
formData.append('username', 'abc123');
formData.append('avatar', fileField.files[0]);
fetch('https://example.com/profile/avatar', {
method: 'PUT',
body: formData
})
.then((response) => response.json())
.then((result) => {
console.log('Success:', result);
})
.catch((error) => {
console.error('Error:', error);
});
xxxxxxxxxx
Public void fileUpload(Stirng path)
{ WebELement upload = driver.findELement; Upload.sendKeys(path) }