1

如何使用selenium.

如何给文件路径?

TextBox的是只读的。我不能直接在textbox.

另外,如何停止 selinum 服务器,直到该文件完全上传。?

我的文件上传字段是一个不可见的字段。我使用 firebug add on 找到了它的代码。

添加文件之前的代码是这样的。

<input id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" type="hidden" name="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" autocomplete="off" value="{'isEnabled':'true','uploadedFiles':[]}">

添加文件(doc文件)后。代码改为

<input id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" type="hidden" name="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState" autocomplete="off" value="{'isEnabled':'true','uploadedFiles':[{"fileInfo":{"FileName":"scope.docx","ContentType":"application/vnd.openxmlformats-officedocument.wordprocessingml.document","ContentLength":12887},"metaData":"/wEFsAF7IlRlbXBGaWxlTmFtZSI6ImZyeWd1NGNqLmt1YSIsIkFzeW5jVXBsb2FkVHlwZU5hbWUiOiJUZWxlcmlrLldlYi5VSS5VcGxvYWRlZEZpbGVJbmZvLCBUZWxlcmlrLldlYi5VSSwgVmVyc2lvbj0yMDExLjEuNTE5LjM1LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTEyMWZhZTc4MTY1YmEzZDQiffOraDjiYXPavAAMYOUAVVhGEKk8"}]}">

这里的 Xpath 是什么?

我尝试使用 xpath id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState"。我使用的代码是

selenium.type("id="ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState","c:\\docfile1.doc");

但它不起作用。

帮我..

4

2 回答 2

1

您可以使用

selenium.type("xpath of text box","path of your file")

或者对于 IDE

command=type
target=xpath_of_text_box
value=Path_of_your_file

例子:

selenium.type("id=cvfile", "D:\\Automation\\resume.doc");
于 2012-04-11T07:13:06.867 回答
1

对此的 XPath 表达式input将是//input[@id='ctl00_ContentPlaceHolder1_AsyncfileUpload_ClientState'].

但是,我担心这行不通,因为 Selenium 通常拒绝使用不可见的元素。此外,hidden <inputs>通常只是预填充数据的容器或脚本验证和编辑数据的容器。

您应该寻找<input type='file' />是否有一些,或者可能是 javascript 处理对封闭元素的点击(但坦率地说,通常情况并非如此 - 脚本倾向于对输入进行编辑,而不是在点击它们时) .

如果找不到,请发布更多代码。最好的东西是SSCCE,所以获取页面的来源并使其裸露,从其中剥离我们不需要的所有内容。我们喜欢代码。我们喜欢任何裸露的东西。

And about the wait for the upload to be complete: There's no such default thing. If the file is sent during a usual form upload (by clicking the Submit button), then the browser will wait. If it is uploaded immediately, you'll have to wait smartly. Realize what changes after a successful upload, then wait for that element/message to appear. With Selenium 2 (WebDriver), this can be done very easily.

于 2012-04-11T13:50:41.227 回答