上传文件 使用的是 python + autoit 模块,这种方式有一个问题,当出现多条任务同时选择文件上传的时候,无法判断那个文件选择窗口的归属,从而出现上传了错误的文件!

解决方法:

要上载文件而不单击上载按钮,在大多数情况下,您可以直接将文件发送到该页上的某个元素。这将是具有input标记名和属性type='file'的元素。不是用户点击的按钮,而是它附近的某个地方。所以你可以试着用这个找到那个元素:

upload_input = driver.find_element_by_xpath('//input[@type="file"]')
upload.send_keys('C:\Users\bodig\Downloads\image1.jpg')

如果您喜欢使用css_selector,您可以使用:

upload_input = driver.find_element_css_selector('input[type="file"]')
upload.send_keys('C:\Users\bodig\Downloads\image1.jpg')

要在你的页面上找到特定的元素,我必须查看网页

posted on 2022-07-20 19:58  木子同学  阅读(445)  评论(0编辑  收藏  举报