有没有一种方法可以上传图像而不必输入图像的绝对路径

时间:2020-11-03 17:56:15

标签: python python-3.x selenium

我正在使用Selenium和Python 3进行编码。我当前上传图像的代码是:

driver.find_element_by_xpath('//*[@name="Filedata"]').send_keys("C:/Users/MyName/PycharmProjects/NikeSNKRS/profilepic.jpg")

我想上传图像而不必输入整个路径,但是如果我尝试以下代码;

driver.find_element_by_xpath('//*[@name="Filedata"]').send_keys("profilepic.jpg")

我收到此错误消息:

selenium.common.exceptions.WebDriverException:消息:未知错误:路径不是绝对的:profilepic.jpg (会话信息:chrome = 86.0.4240.183)

0 个答案:

没有答案