Selenium sendkeys stop working for browse dialog box

Issue

I had this bit of code that works for years but all of a sudden stopped. The element is found and keys are sent (no error) but no text shows in browse dialog box. Interfacing with popular photo sharing website. Selecting a picture for the post. I’ve tried clear and clicking suggestions from other posts but it errors. I also tried changing my file from a .jpg to jpeg like mentioned in other posts.

image_filename = 'C:\\filefolder\\subfolder\\image.jpeg'
driver.find_element(By.TAG_NAME, 'input').send_keys(image_filename) 
driver.find_element(By.XPATH, "//input[@type='file']").send_keys(image_filename)

<div class="_a3gq"> <div class="_a3gq"> <form enctype="multipart/form-data" method="POST" role="presentation"> <input accept="image/jpeg" class="_ac69" type="file"> </form></div><section class="_a997 _a998"><div></div>

Solution

I used pywinauto to get this working. Thank you for all the comments. They made me realize I couldn’t do it with Selenium

image_filename = 'myimagename.jpg'
app = pywinauto.application.Application().connect(title_re='Open')
window = app.Dialog
window.SetFocus()
window.TypeKeys(image_filename)
logger.info('image selected')
app.Dialog.Open.click()

Answered By – CoffeeBean

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published