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

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

问题描述

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

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...

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

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 Settings\pcname\Desktop\ffdlt\test.jpeg")

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

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