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
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.