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