Execute JS, display the hidden input box via JS, or assign a value to input

Source: Internet
Author: User

Some of the input boxes are hidden during testing, and if you assign them directly, you will not find the input box, which causes the script to run unsuccessfully.

For example, the following Password entry box:

Login Password input box is divided into two input, the following is the prompt, the above is the real password input box, two input is linkage, the default above input box is hidden, if the direct assignment is not found this input, So it is necessary to change the display property of input from none to block to show it and then assign it to him, or give him a value property directly to assign it.

First, change the display property by JS to show input

Js= "var P=document.getelementbyid (' Password ');p. style.display= ' block ';
Driver.execute_script (JS);

Note: These two sentences can be used to display the "Password" input box, and then can be assigned directly through the Send_keys. JS is Custom, p is also a function of its own definition, you can take a name. Of course, it's possible to connect the two sentences together.

Driver.execute_script ("var P=document.getelementbyid (' Password ');p. style.display= ' block ';");

Second, do not display input, directly to input assignment, plus value

Driver.execute_script ("var Js1=document.getelementbyid (' Txt_confirmpassword '); js1.value= ' 123456 ';");

Driver.execute_script ("var Js2=document.getelementbyid (' ConfirmPassword '); js2.value= ' 123456 ';");

Description: Defines a function that assigns a value to input by js.value= "".

Execute JS, display the hidden input box via JS, or assign a value to input

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.