【问题标题】:uploading photos to Craigslist with Python and Selenium使用 Python 和 Selenium 将照片上传到 Craigslist
【发布时间】:2016-03-04 20:00:34
【问题描述】:

在 windows10 上使用 python3、selenium 和 firefox: 这个程序很简单。它直接跳转到 craigslists 的“发布新列表”页面,上传多张照片,然后提交。我遇到的问题是我无法使用 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)

我一直在做一些阅读,我得到了我需要使用 send_keys() 到“输入文件”的要点,但我对硒和一般编程仍然很陌生,以至于我不完全理解这个概念。我的想法是使用 AutoIt 的 SendKeys,但我什至无法弄清楚为什么 AutoIt 无法安装到我的计算机上。所以我希望有人能对如何发送预先确定的路径名​​有所了解,这样我就可以上传照片了。任何帮助表示赞赏,谢谢!

【问题讨论】:

  • 您是如何完成最初的单选按钮步骤的,它要求所有者/您出售什么/哪个类别?

标签: selenium python-3.5 craigslist


【解决方案1】:

您不应使用<button> 元素进行操作,而应使用<input>,因此请使用以下代码:

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

【讨论】:

  • “html5_1ad1qt6re13snm058nqev3tb3”从何而来?我试过这个,得到一个错误:'无法定位元素:{“method”:“id”,“selector”:“html5_1ad1qt6re13snm058nqev3tb3”}'
  • 哦...我猜这个Id 是动态变化的。试试browser.find_element_by_xpath("//input[@type='file']").send_keys(filepath)
猜你喜欢
  • 2011-04-02
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 2013-07-15
  • 2021-02-06
  • 2011-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多