如何使用selenium测试工具在Web应用程序上上传图片?我正在使用python.
我尝试了很多东西,但没有任何效果.
我是selenium的新手,我有一个脚本可以将文件上传到服务器.
在ide版本中说它上传文件,但当我导出测试用例为python 2/unittest/webdriver时,它不会上传它..
它不会给我任何错误,只是不上传它...
python脚本是:
driver.find_element_by_id("start-upload-button-single").click()
driver.find_element_by_css_selector("input[type=\"file\"]").clear()
driver.find_element_by_css_selector("input[type=\"file\"]").send_keys("C:\\\\Documents and Settings\\\\pcname\\\\Desktop\\\\ffdlt\\\\test.jpeg")
Run Code Online (Sandbox Code Playgroud)
我搜索了解决方案,但除了将其与AutoIt或AutoHotKey集成之外,我还没有找到任何解决方案......
第一行打开Firefox的文件上传框.
无法弄清楚如何在那里上传文件?需要拖拽或直接通过对话框选中
我已经尝试过这个页面的方法: 在 Python 中使用 Selenium 上传文件
代码:
file_button = browser.find_element_by_id('fileUploadProxy')
file_button.send_keys('/Users/home/Downloads/1-Students-and-Parent-Email.csv')
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Traceback (most recent call last):
File "test.py", line 110, in <module>
upload_students_results('Surname, Name')
File "test.py", line 91, in upload_students_results
file_button.send_keys('/Users/home/Downloads/1-Students-and-Parent-Email.csv')
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 349, in send_keys
'value': keys_to_typing(value)})
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 493, in _execute
return self._parent.execute(command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 249, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot focus element
(Session info: chrome=58.0.3029.96)
(Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac …Run Code Online (Sandbox Code Playgroud)