Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中使用Selenium自动上载文件_Python_Selenium - Fatal编程技术网

在Python中使用Selenium自动上载文件

在Python中使用Selenium自动上载文件,python,selenium,Python,Selenium,我正在尝试使用Python中的SeleniumWebDriver自动上传文件。现在,我有以下代码: url = "https://uploadfiles.io/" driver = webdriver.Firefox(executable_path="/path/to/firefoxdriver") driver.get(url) getForm = driver.find_element_by_xpath("//form[@class='dropzone needsclick dz-click

我正在尝试使用Python中的SeleniumWebDriver自动上传文件。现在,我有以下代码:

url = "https://uploadfiles.io/"
driver = webdriver.Firefox(executable_path="/path/to/firefoxdriver")
driver.get(url)
getForm = driver.find_element_by_xpath("//form[@class='dropzone needsclick dz-clickable']")
getForm.send_keys("/path/to/somefile")
然而,这不起作用。出于某种奇怪的原因,它试图找到我正在发送的文本,以便在页面上发送_键(比如当您执行command+f时)

正如这里所解释的:,此表单不是输入,因此您可能需要以不同的方式处理它。
如果打开时输入字段处于焦点位置,机器人应该可以工作。

您必须重新检查X路径选择器,现在该类已更改为[ufzone needsclick dz clickable]。选择正确的选择器,您将获得

共享相关HTML