uploading photos to Craigslist with Python and Selenium

一个人想着一个人 提交于 2019-12-07 07:46:17

问题


using python3, selenium with firefox on windows10: this program is simple. it jumps directly to craigslists 'post a new listing' page, uploads multiple photos, then submit. the problem im having is that i cannot control a dialog box to navigate to the correct file with selenium.

browser = webdriver.Firefox()
browser.get('https://post.craigslist.org/k/lPbhT6Lh5RGBKb-uS1zr0g/g2NjN?lang=en&cc=us&s=editimage')
#opens to craigslists 'Upload/Edit Images' page

add_imgs_btn = browser.find_element_by_id('plupload')
#find the 'add images' button

add_imgs_btn.click()
#clicks the button which opens the dialog box, which is not operable from selenium
add_imgs_btn.send_keys(filepath)

Ive been doing some reading and i get the gist that i need to use send_keys() to the 'input file', but im still so new with selenium and programming in general, that i dont totally understand the concept. my idea was to use SendKeys from AutoIt, but i cant even figure out why AutoIt wont install to my computer. so im hoping someone can shed a little light on how to send the pre-decided pathname so i can upload photos. any help is appreciated, thanks!


回答1:


You should not operate with <button> element, but with <input> instead, so use following code:

browser.find_element_by_xpath("//input[@type='file']").send_‌​keys(filepath)


来源:https://stackoverflow.com/questions/35805049/uploading-photos-to-craigslist-with-python-and-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!