Since the element is not visible, direct interaction from the UI using methods like sendKeys
is not possible. One workaround is to modify the element attribute in the background by invoking the HTML DOM API.
let upload_element = driver.findElement(By.id('avatar-upload'))
let file_path = '/home/user/Desktop/smg935-0hero-0930.jpeg'
driver.executeScript('return arguments[0].value=arguments[1];', upload_element, file_path)
However, this method has a drawback as it operates in the background and does not trigger key/mouse events associated with the element. For instance, if the upload widget relies on key events to determine whether a user has selected a file before allowing them to click the upload button, then the background approach may not be effective in such scenarios.