selenium webdriver上传文件 [英] selenium webdriver upload file

查看:35
本文介绍了selenium webdriver上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 selenium 的新手,我有一个将文件上传到服务器的脚本.

I am new to selenium, I have a script that uploads a file to a server.

在 ide 版本中,它会上传文件,但是当我将测试用例导出为 python 2/unittest/webdriver 时,它不会上传它..

In the ide version sort of speak it uploads the file, but when I export test case as python 2 /unittest / webdriver it doesn't upload it..

它没有给我任何错误,只是没有上传...

It doesn't give me any errors, just doesn't upload it...

python 脚本是:

The python script is:

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")

我搜索了解决方案,但除了将其与 AutoIt 或 AutoHotKey 集成之外,我没有找到任何解决方案...

I searched for solutions but I haven't found any except integrating it with AutoIt or AutoHotKey...

第一行打开火狐的文件上传框.

The first line opens the File Upload Box of Firefox.

推荐答案

你的代码非常适合我(我用 Firefox、Chrome 驱动程序测试过)

Your code work perfectly for me (I test it with Firefox, Chrome driver)

我怀疑的一件事是过多的反斜杠()转义.

One thing I supect is excessive backslash() escape.

尝试以下操作:

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")

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(r"C:Documents and SettingspcnameDesktopffdlt	est.jpeg")

这篇关于selenium webdriver上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆