SELENIUM2 using Javascriptexecutor to perform on page javascipt

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.