"Turn" selenium featured-jquery Selector

Source: Internet
Author: User
Tags jquery library

The Juqery selector is a very important feature in the jquery library. The jquery selector is based on the css1-3 selector, plus some additional selectors. These selectors are very similar to CSS selectors, allowing developers to easily and quickly identify elements on the page. You can also locate an element in HTML as a single element or as a collection of elements. jquery selectors can be used on browsers that do not support CSS selectors.

1. Use the jquery selector when you need to pay attention to the test page has not loaded the jquery library

Program Checklist-Determine if the jquery library is loaded:

 Packagecom. Test.function; ImportOrg.openqa.selenium.JavascriptExecutor;ImportOrg.openqa.selenium.WebDriver;ImportOrg.openqa.selenium.chrome.ChromeDriver;//determine if the test page loads the jquery library, and if not, manually load Google's online library Public classJQuery {StaticString URL1 = "http://www.baidu.com"; StaticString url2 = "http://weibo.kedacom.com"; StaticString DriverPath = "F:\\autotest\\selenium\\chromedriver.exe"; StaticWebdriver Driver; //test function     Public Static voidMain (String args[]) {JQuery J=NewJQuery (); //Loading Chrome DriversSystem.setproperty ("Webdriver.chrome.driver", DriverPath); Driver=NewChromedriver ();        Driver.get (URL1);        J.injectjqueryifneeded ();        Driver.navigate (). to (URL2);        J.injectjqueryifneeded ();    Driver.quit (); }     //load jquery    Private voidinjectjqueryifneeded () {if(!jqueryisloaded ())        {injectjquery (); }    }     /** Determine if jquery is loaded * Returns true to indicate that jquery has been loaded*/     PublicBoolean jqueryisloaded () {Boolean loaded; Try{loaded= (Boolean) ((javascriptexecutor) driver). Executescript ("Return jQuery ()!=null"); System.out.println ("The page itself has been loaded with jquery"); }Catch(Exception e) {loaded=false; }        returnloaded; }     //inject jquery     Public voidInjectjquery () {//spell the HTML that loads jquery in the head, fix the wordingString jquery = "var headid=document.getelementsbytagname (\" head\ ") [0];" + "var newscript = Documen T.createelement (' script '); "+" newscript.type= ' text/javascript '; "+" Newscri pt.src= ' http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js '; "+" Headid.appendchild (NE WScript); "; //Execute JS((javascriptexecutor) driver). Executescript (jquery); System.out.println ("Manually load jquery"); }}

Original: http://www.ostest.cn/archives/256

"Turn" selenium featured-jquery Selector

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.