Selenium RC>如何使用attachFile()上传文件

Saa*_*ara 8 javascript selenium-rc

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

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.
Run Code Online (Sandbox Code Playgroud)

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

Saa*_*ara 1

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

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

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

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

selenium.keyDownNative("16"); //切换开

selenium.keyPressNative("67"); // c 移位使其变为 C

selenium.keyPressNative("59"); // ; Shift 可以实现:(你不能直接使用冒号)

selenium.keyUpNative("16"); // 关闭

selenium.keyPressNative("47"); // 斜线

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

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

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

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

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

selenium.keyPressNative("47"); // 斜线

selenium.keyDownNative("16"); //切换开

selenium.keyPressNative("70"); // f 移位使其变为 F

selenium.keyUpNative("16"); // 关闭

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

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

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

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

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

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

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

selenium.keyPressNative("10"); // 进入

selenium.keyReleaseNative("10"); // 进入

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