Selenium RC > how to upload file using attachFile()

后端 未结 8 803
谎友^
谎友^ 2021-02-04 14:02

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:/         


        
8条回答
  •  猫巷女王i
    2021-02-04 14:18

    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("text box locator");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

提交回复
热议问题