【发布时间】:2018-06-18 14:36:07
【问题描述】:
我正在使用 Selenium 和 Python 在 Instagram 上测试一些网络抓取。
在这种情况下,我想上传一张图片。
通常您必须单击上传图标并从窗口中选择文件。如何使用 Selenium 进行管理?
我试过了:
driver.find_element_by_class_name("coreSpriteFeedCreation").send_keys('C:\\path-to-file\\file.jpg')
还有find_element_by_xpath,但我得到一个例外:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
我也只尝试了click(),但没有任何反应。
有什么想法吗?
编辑
感谢@homersimpson 的评论,我尝试了这个:
actions = ActionChains(driver)
element = driver.find_element_by_class_name("coreSpriteFeedCreation")
actions.move_to_element(element)
actions.click()
actions.send_keys('C:\\path-to-file\\file.jpg')
actions.perform()
现在出现选择文件的窗口。问题是我想避开这个窗口,直接给出我的文件的路径。
【问题讨论】:
-
感谢@homersimpson,我编辑了我的问题
-
你能显示文件上传窗口的 HTML sn-p 吗?
标签: python selenium selenium-webdriver web-scraping instagram