SELENIUM2 Learning -011-webui Automation Practical instance -009-javascript one of the applications in Selenium Automation (assigned value)

Source: Internet
Author: User

Usually when writing Selenium WebUI automation scripts, some elements are not easy to locate elements, or some elements are hidden (when the value of Webelement.gettext () is obtained at this time, the returned result is empty), for the daily UI The writing of automation scripts has a certain degree of impact. If you have a certain pre-development base, can Ken think of using JavaScript scripts to manipulate elements? The answer is yes, Slenium has provided for the small owners to execute the JS script function, that is javascriptexecutor, the small owners only need to convert Webdriver to Javascriptexecutor type, call its Executescript method, you can execute the JS script. is not very convenient AH ^_^

This article mainly in Yixun net modifies input text box content to carry on a simple example explanation, hoped can have the revelation and the help to the small master. If there is any deficiency, please ask the great God to correct me, I appreciate it!

The following is a Java automated test script instance source code for one of the application examples of JavaScript in Selenium automation (Assignment), please see!

1  PackageMain.aaron.demo.javascript;2 3 Importorg.openqa.selenium.By;4 ImportOrg.openqa.selenium.JavascriptExecutor;5 Importorg.openqa.selenium.WebElement;6 Importorg.testng.annotations.Test;7 8 Importmain.aaron.sele.core.TestCase;9 Ten /** One * JavaScript Application examples in Selenium automation A  *  -  * @authorAARON.FFP -  * @versionV1.0.0:autoseleniumdemo main.aaron.demo.javascript Javascript.java, 2015-6-17 00:24:59 Exp $ the  */ -  Public classJavascriptextendstestcase{ -     //Execute JavaScript script, enter query content IPhone 6 Plus -     PrivateString JScript = "document.getElementById (' Q_show '). value= ' IPhone 6 Plus '"; +     PrivateString baseUrl = "http://www.yixun.com/"; -      +     /** A * JavaScript Assignment at      *  -      * @authorAARON.FFP -      * @versionV1.0.0:autoseleniumdemo main.aaron.demo.javascript Javascript.java testjscript, 2015-6-17 12:37:57 Exp $ -      *  -      * @throwsinterruptedexception -      */ in @Test -      Public voidTestjscript ()throwsinterruptedexception{ to          This. Webdriver.get ( This. BaseUrl); +          -Webelement search = This. Webdriver.findelement (By.cssselector (". Mod_search_btn")); the  *          This. Execjavascript (JScript); $         Panax Notoginseng Search.Click (); -  the          This. Webdriver.close (); +          This. Webdriver.quit (); A     } the      +     /** - * Execute JScript scripts $      *  $      * @authorAARON.FFP -      * @versionv1.0.0:autouiselenium main.java.aaron.sele.core Seleniumcore.java execjavascript, 2015-6-17 00:25:38 Exp $ -      *  the      * @paramJScript Scripts -      */Wuyi      Public voidexecjavascript (String JScript) { the((Javascriptexecutor) This. Webdriver). Executescript (JScript); -     } Wu}
one of the application examples in Selenium automation (assigned value)

document.getElementById (' Q_show '). value= ' iphone 6 Plus ' The purpose of this JS script is to find the Q_show Web search box by id= ' Yixun ' and assign the iphone 6 Plus.

PS: When using the above source, please add the code to launch the browser yourself .

At this point, theWebUI automation function test Script No. 009-javascript in Selenium automation of one of the application examples of input assignment successfully completed, I hope this article can give beginners Selenium you a reference.

Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^

Selenium2 Learning -011-webui Automation Practical instance -009-javascript one of the applications in Selenium Automation (Assignment)

Related Article

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.