使用 Selenium 和 Python 上传文件到 shopify
Uploading a file to shopify with Selenium and Python
我在使用 selenium 将文件上传到 shopify 时遇到困难。Selenium 似乎无法找到我需要将文件添加到的输入元素,我假设这与输入类型=隐藏部分有关?见图。
我试过很多这样的变体
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='files_']"))).send_keys("DIR/myfile.pdf')
并尝试执行脚本以尝试取消隐藏输入
container = browser.find_element_by_xpath("//input[@type='hidden']")
browser.execute_script("arguments[0].type = 'text';", container)
等等等等
shopifyapi 的文档不是最好的,我也不是最好的编码员。任何帮助都将不胜感激。
谢谢!
要上传文件,您必须将密钥发送到类型为 file
的 input
,通常它是隐藏的。将 element_to_be_clickable
替换为 presence_of_element_located
并尝试发送如下代码中的密钥:
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input#files_"))).send_keys("DIR/myfile.pdf')
我在使用 selenium 将文件上传到 shopify 时遇到困难。Selenium 似乎无法找到我需要将文件添加到的输入元素,我假设这与输入类型=隐藏部分有关?见图。
我试过很多这样的变体
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='files_']"))).send_keys("DIR/myfile.pdf')
并尝试执行脚本以尝试取消隐藏输入
container = browser.find_element_by_xpath("//input[@type='hidden']")
browser.execute_script("arguments[0].type = 'text';", container)
等等等等
shopifyapi 的文档不是最好的,我也不是最好的编码员。任何帮助都将不胜感激。 谢谢!
要上传文件,您必须将密钥发送到类型为 file
的 input
,通常它是隐藏的。将 element_to_be_clickable
替换为 presence_of_element_located
并尝试发送如下代码中的密钥:
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "input#files_"))).send_keys("DIR/myfile.pdf')