无法使用python在selenium上传图像

时间:2014-01-12 18:47:07

标签: python selenium

我正在尝试使用python中的webdriver.Firefox上传照片:

upload_img_first = '/home/emin/Desktop/test/me.jpg'

driver.find_element_by_xpath('//button[contains(@class, "button-class")]').send_keys(os.getcwd()+upload_img_first)

红色栏出现在浏览器底部,图像地址为/home/emin/Desktop/test/me.jpg

有什么问题?

1 个答案:

答案 0 :(得分:1)

假设send_keys被发送到正确的元素,它就像upload_image_first变量是绝对路径一样松散。当你send_keys时,你正在连接到那个绝对路径的当前路径。

所以,如果你从/ home / emin运行这个程序,你可以发送_key到/home/emin/home/emin/Desktop/test/me.jpg