SELENIUM2 Learning -008-webui Automation Practical Example-006-Yixun Login Frame Processing

Source: Internet
Author: User

This article mainly describes the writing process of Selenium Automated test script in Java, when the frame label causes the page to locate the failure, prompt nosuchelementexception, the page element before the location of frame processing, that is WEBDRIVER.SWTI Summary usage of chto.frame ().

Hope to be able to beginners Selenium2 WebUI automated test programming of the pro-helpful. If there is any deficiency, please ask the great God to correct me, I appreciate it!

In my previous page element positioning sample article (Selenium2 Web element positioning and XPath Writing demo example) mentioned in the Yixun login when there is a pit, do not know if you remember? If you have carefully read the Yixun login page source code, it is not difficult to find the login information entry box is embedded in the frame. So how do we locate the page elements in this type of frame in the actual scripting? The HTML display for the page is as follows:

In fact, it is very simple: switch to the corresponding frame, and then locate the element, after performing the corresponding operation, it is recommended to return its default defaultcontent.

Gossip less, directly on the code, please pro-reading ^_^, the source code is as follows:

1 /**2 * AARON.FFP Inc.3 * Copyright (c) 2004-2015 All rights Reserved.4  */5  PackageMain.java.aaron.sele.demo;6 7 Importjava.util.Arrays;8 ImportJava.util.concurrent.TimeUnit;9 Ten Importorg.openqa.selenium.By; One ImportOrg.openqa.selenium.WebDriver; A ImportOrg.openqa.selenium.chrome.ChromeDriver; - Importorg.openqa.selenium.chrome.ChromeOptions; - Importorg.openqa.selenium.remote.DesiredCapabilities; the  - /** - * UI Automation Functional Test Script: Introducing Frame processing with Yixun login -  *  + * The steps to implement Chrome browser startup are as follows: - * 1. Set the installation path for Chrome + * 2. Set Chrome's Webdriver A * 3. Parametric start Chrome at * 4. Open the Easy link - * 5. Frame switching via webdriver.switchTo.frame () - * 6. Enter your account and password - * 7. Close and Exit -  *    -  * @authorAARON.FFP in  * @version$Id: Selenium_framedemo.java, V0.1 2015-1-21 13:23:54 AARON.FFP Exp $ -  */ to  Public classSelenium_framedemo { +     Private Staticwebdriver cd; -     Private StaticString BaseUrl;//Baidu Home Site the     Private StaticString username; *     Private StaticString Userpass; $ Panax Notoginseng     /** - * Chrome webdriver settings, URL and search content initialization, open Chrome browser the      */ +      Public Static voidChromestart () { A         /*set the location of the chrome boot file, and if not set, take chrome from the default installation directory*/ theSystem.setproperty ("Webdriver.chrome.bin", "C:/Program Files (x86)/google/chrome/application/chrome.exe"); +         /*setting the location of Chrome Webdirver*/ -System.setproperty ("Webdriver.chrome.driver", "C:/windows/system32/chromedriver.exe"); $          $         /*Baidu Home Site assignment Value*/ -BASEURL = "Https://base.yixun.com/login.html"; -          the         /*start the Chrome browser*/ -cd =NewChromedriver (Chromeoptions ());Wuyi          the         /** - * Login account number and password assignment, the actual application needs to be correctly assigned Wu          */ -Username = "231333574"; AboutUserpass = "Input Userpass"; $     } -  -     /** - * Main method entrance A      * @paramargs +      * @throwsinterruptedexception the      */ -      Public Static voidMain (string[] args)throwsinterruptedexception { $         /*Start Chrome*/ the Chromestart (); the          the         /*perform Yixun network logon operations*/ the icsonlogin (BASEURL, username, userpass); -          in         /*Waiting to load*/ theCd.manage (). Timeouts (). implicitlywait (5, timeunit.seconds); the          AboutTimeUnit.SECONDS.sleep (5); the          the         /*Close Chrome*/ the chromequit (); +     } -      the     /**Bayi * Yixun Login and enter your account and password the      *  the      * @parambaseUrl: Login URL -      * @paramUsername: Account -      * @paramuserpass: Password the      */ the      Public Static voidIcsonlogin (String baseUrl, String username, string userpass) { the Cd.get (BASEURL); the          -         /*Frame Toggle*/        theCd.switchto (). FRAME ("Id_iframe_login"). SwitchTo (). FRAME ("Qq_login_iframe"); the          the         /*Enter your account*/94Cd.findelement (By.id ("U") . SendKeys (username); the          the         /*Enter Password*/ theCd.findelement (By.id ("P") . SendKeys (userpass);98     } About      -     /**101 * Set the Chrome browser's startup parameters, set the browser window to maximize after startup, ignore the authentication error warning102      * 103      * @returnchromeoptions Chrome parameter Settings104      */ the      Public Staticchromeoptions chromeoptions () {106Chromeoptions options =Newchromeoptions ();107Desiredcapabilities capabilities =desiredcapabilities.chrome ();108Capabilities.setcapability ("Chrome.switches", Arrays.aslist ("--start-maximized"));109          /*Browser Maximization*/ theOptions.addarguments ("--test-type", "--start-maximized");111          /*ignore the Chrome browser's authentication error*/ theOptions.addarguments ("--test-type", "--ignore-certificate-errors");113           the          returnoptions; the      } the     117     /**118 * Close and exit Chrome119      */ -      Public Static voidChromequit () {121         /*Close Chrome*/122 cd.close ();123         /*quit Chrome*/124 cd.quit (); the     }126}
Selenium-java Script Frame processing: Yixun Login Actual instance source code

At this point,WebUI automation function test Script No. 006-Yixun Login Frame processing 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 -008-webui Automation Practical Example-006-Yixun Login Frame Processing

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.