SELENIUM2 Learning -036-webui Automation Practical instance -034-javascript in Selenium Automation application example of six (get JS execution result return value)

Source: Internet
Author: User
Tags close page testng

Selenium to get the JavaScript return value is very simple, just need to return the data in the JS script can be returned, and then through the method to return JS execution results, the method source code is as follows:

1     /**2 * Get Object of return from JS3      * 4      * @authorAARON.FFP5      * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java execjsr, 2015-8-9 1:39:17 Exp $6      * 7      * @paramJs:return_js8      * 9      * @returnObjectTen      */ One      PublicObject EXECJSR (String js) { A         return((Javascriptexecutor) This. Webdriver). Executescript (JS); -}

The test steps are summarized as follows:

    1. Start the Chrome browser
    2. Open the homepage of Yi Xun net
    3. Executes a JavaScript script and gets the return value
    4. Close page
    5. Exit Webdriver

The test source for the method is as follows:

1 /**2 * AARON.FFP Inc.3 * Copyright (c) 2004-2015 All rights Reserved.4  */5  PackageMain.aaron.demo.javascript;6 7 ImportMain.aaron.sele.core.SeleniumCore;8 9 ImportOrg.openqa.selenium.chrome.ChromeDriver;Ten ImportOrg.testng.annotations.AfterClass; One ImportOrg.testng.annotations.BeforeClass; A Importorg.testng.annotations.Test; -  - /** the  *  -  * @authorAARON.FFP -  * @versionV1.0.0:autoseleniumdemo main.aaron.demo.javascript Jquery.java, 2015-7-27 13:31:31 Exp $ -  */ +  Public classJqueryextendsseleniumcore{ -String JQ = "Webelement = $ ('. Btn-cor-1 ') [0];" + +"Return webelement.offsettop + '; ' + Webelement.offsetleft + '; ' +" + A"Webelement.offsetheight + '; ' + webelement.offsetwidth"; atString baseUrl = "http://www.yixun.com/"; -      - @BeforeClass -      Public voidBeforeclass ()throwsinterruptedexception{ -          This. Webdriver =Newchromedriver (); -          This. Webdriver.manage (). window (). Maximize (); in          This. Webdriver.get (BASEURL); -Thread.Sleep (5000); to     } +      - @AfterClass the      Public voidAfterclass () { *          This. Webdriver.close (); $          This. Webdriver.quit ();Panax Notoginseng     } -      the     /** + * Get Return of Execute JavaScript A      *  the      * @authorAARON.FFP +      * @versionV1.0.0:autoseleniumdemo main.aaron.demo.javascript Jquery.java test_jsreturn, 2015-8-8 15:59:51 Exp $ -      * $      */ $ @Test -      Public voidTest_jsreturn () { -System.out.println ("\nstart test_jsreturn ..."); theSystem.out.println ( This. EXECJSR (JQ)); -     }Wuyi}

The execution results are as follows:

Start Test_jsreturn ... 717;1396;30;100

At this point, theWebUI automation function test script section 034-javascript in the Selenium Automation application Example six (get the JS execution result return value) successfully completed, I hope this article can give beginners Selenium A reference for you.

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 -036-webui Automation Practical instance -034-javascript in Selenium Automation application example of six (get JS execution result return value)

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.