python - Selenium file upload url "path is not absolute" -
i'm trying upload file facebook group selenium chromedriver.
driver.find_element_by_xpath("//input[@type='file']").send_keys("http://www.peta.org/wp-content/uploads/2013/10/goat_2d00_list_2d00_1.jpg")
but throws exception this:
selenium.common.exceptions.webdriverexception: message: unknown error: path not absolute:
i'm on windows 10, chrome 44.0.2403.130, chromedriver 2.16.333243, selenium 2.47.1
so how can upload images urls ? (without having explicitly download it)
nope, way can upload files from local machine:
driver.find_element_by_xpath("//input[@type='file']").send_keys("/path/to/the/file")
download image first, upload. instance:
with urllib
import os import urllib base_dir = "/path/to/dir/" path_to_image = os.path.join(base_dir, "upload.jpg") urllib.urlretrieve("http://www.peta.org/wp-content/uploads/2013/10/goat_2d00_list_2d00_1.jpg", path_to_image) driver.find_element_by_xpath("//input[@type='file']").send_keys(path_to_image)
with requests
import os import requests base_dir = "/path/to/dir/" path_to_image = os.path.join(base_dir, "upload.jpg") response = requests.get("http://www.peta.org/wp-content/uploads/2013/10/goat_2d00_list_2d00_1.jpg") if response.status_code == 200: f = open(base_dir + path_to_image, 'wb') f.write(response.content) f.close()
Comments
Post a Comment