硒RC>如何使用attachFile()上传文件 [英] Selenium RC > how to upload file using attachFile()

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

问题描述

我正在使用Selenium RC和Junit框架。我正在尝试使用attachFile()方法上传文件。

I am using Selenium RC with Junit framework. I am trying to upload a file using attachFile() method.

attachFile: (Information collected from selenium API http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/java/com/thoughtworks/selenium/Selenium.html#attachFile(java.lang.String,%20java.lang.String))

void attachFile(java.lang.String fieldLocator,
            java.lang.String fileLocator)

Sets a file input (upload) field to the file listed in fileLocator

Parameters:
    fieldLocator - an element locator
    fileLocator - a URL pointing to the specified file. Before the file can be set
  in the input field (fieldLocator), Selenium RC may need to transfer the file to 
  the local machine before attaching the file in a web page form. This is common in 
  selenium grid configurations where the RC server driving the browser is not the 
  same machine that started the test. Supported Browsers: Firefox ("*chrome") only.

任何人都可以告诉我如何定义fileLocator。我没有在这里指定要指定的URL。如果可能请给我一个例子。

Can anyone please tell me how to define "fileLocator". I am not getting which URL to be specify over here. Please give me an example if possible.

推荐答案

我得到了解决方案,使用selenium.focus方法和selenium.keyPressNative / keyReleaseNative方法。

I got solution for this, use selenium.focus method and the selenium.keyPressNative/keyReleaseNative methods.

您需要使用以下方法将焦点放在文本框中:

You will need to give focus to the text box using:

selenium.focus(文本框定位器);

selenium.focus("text box locator");

然后,如果您的输入文件是C:\ tools \ .File.txt,则需要输入如下字母:

Then if your input file is C:\tools\File.txt you need to type the letters like so:

selenium.keyDownNative(16); // SHIFT ON

selenium.keyDownNative("16"); //SHIFT ON

selenium.keyPressNative(67); // c shift使它成为C

selenium.keyPressNative("67"); // c shift makes it C

selenium.keyPressNative(59); //; Shift使它:(你不能直接冒号)

selenium.keyPressNative("59"); // ; Shift makes it : (you can't do colon directly)

selenium.keyUpNative(16); // SHIFT OFF

selenium.keyUpNative("16"); // SHIFT OFF

selenium.keyPressNative(47); //斜杠

selenium.keyPressNative("47"); // slash

selenium.keyPressNative(84); // t

selenium.keyPressNative("84"); // t

selenium.keyPressNative(79); // o

selenium.keyPressNative("79"); // o

selenium.keyPressNative(79); // o

selenium.keyPressNative("79"); // o

selenium.keyPressNative(76); // l

selenium.keyPressNative("76"); // l

selenium.keyPressNative(83); // s

selenium.keyPressNative("83"); // s

selenium.keyPressNative(47); //斜杠

selenium.keyPressNative("47"); // slash

selenium.keyDownNative(16); // SHIFT ON

selenium.keyDownNative("16"); //SHIFT ON

selenium.keyPressNative(70); // f shift使它F

selenium.keyPressNative("70"); // f shift makes it F

selenium.keyUpNative(16); // SHIFT OFF

selenium.keyUpNative("16"); // SHIFT OFF

selenium.keyPressNative(73); // i

selenium.keyPressNative("73"); // i

selenium.keyPressNative(76); // l

selenium.keyPressNative("76"); // l

selenium.keyPressNative(69); // e

selenium.keyPressNative("69"); // e

selenium.keyPressNative(46); //。

selenium.keyPressNative("46"); // .

selenium.keyPressNative(84); // t

selenium.keyPressNative("84"); // t

selenium.keyPressNative(88); // x

selenium.keyPressNative("88"); // x

selenium.keyPressNative(84); // t

selenium.keyPressNative("84"); // t

selenium.keyPressNative(10); //输入

selenium.keyPressNative("10"); // Enter

selenium.keyReleaseNative(10); //输入

selenium.keyReleaseNative("10"); // Enter

我已经用'Enter'字符结束了sequqnce。有时这不起作用,因此您可能需要单击按钮(如果您知道它的元素定位器)。

I've ended the sequqnce with an 'Enter' character. Sometimes this doesn't work so you may need to click the button (if you know the element locator for it).

这篇关于硒RC>如何使用attachFile()上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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