Objective:
1. Execute a section of JS to change the HTML
2. Some non-standard controls cannot use the Selenium2 API, you can execute JS method to replace
Main operation:
Javascriptexecutor j = (javascriptexecutor) driver;
J.executescript ("alert (' Hellow rold! ')");
Description
1. Executescript The parameter of this method is a string, for a section of JS code
2. Note that the JS code needs to be written from the requirements of the underlying project!
Executescript (java.lang.String arg0, java.lang.Object ... arg1);
The second parameter is a variable parameter,
1. The second parameter is written as follows:
jdk1.6~1.7
do not use a second argument
executor.executescript ("alert (' AAA ');");
Use the second parameter:
executor.executescript ("alert (' AAA ');", "argument1", "argument2");
executor.executescript ("alert (' AAA ');", New object[]{"Argument1", "Argument2"});
JDK1.8
do not use a second argument
executor.executescript ("alert (' AAA ');", New object[]{});
Use the second parameter:
executor.executescript ("alert (' AAA ');", New object[]{"Argument1", "Argument2"});
2. The role of the second parameter.
in fact, the first parameter is given the JavaScript code to pass in the value, these values can be obtained by using arguments[0],arguments[1 in JavaScript].
executor.executescript ("alert (arguments[0]);", New object[]{"aa111"});
SELENIUM2 using Javascriptexecutor to perform on page javascipt