Add Jquery libraries to Selenium
-
08-10-2019 - |
문제
Could someone please point me on how to add Jquery libraries to Selenium? I did search online and below are the steps I have followed so far. I am not sure what to do next. After these changes, how do I build the selenium jar back with the changes?
- Unzipped selenium 2.04.jar
- Copied contents of jQuery.js in user-extensions.js
JQuery locator to the Selenium core in the runSeleniumTest() function of the selenium-remoterunner.js file like below,
function runSeleniumTest() { ... selenium.doAddLocationStrategy("jquery", " var loc = locator; var attr = null; var isattr = false; var inx = locator.lastIndexOf('@');
if (inx != -1) { loc = locator.substring(0, inx); attr = locator.substring(inx + 1); isattr = true } var selectors = loc.split('<'); var found = $(inDocument); for (var i = 0; i < selectors.length; i++) { if (i > 0) {found = $(found.parents()[0]); } if (jQuery.trim(selectors[i]) != '') found = found.find(selectors[i]); } if (found.length > 0) { if (isattr) { return found[0].getAttributeNode(attr); } else { return found[0]; } } else { return null; } "); ... }
해결책
To update a file in a jar, refer here.
Essentially:
The basic command for adding files has this format:
jar uf jar-file input-file(s) In this command:
The u option indicates that you want to update an existing JAR file. The f option indicates that the JAR file to update is specified on the command line. If the f option is not present, the Jar tool will expect a JAR filename on stdin. jar-file is the existing JAR file that's to be updated. input-file(s) is a space-deliminated list of one or more files that you want to add to the Jar file.
You could perhaps also just add the JQuery js file as a Selenium user extension. Refer here.
Just remember to start the Selenium RC server using the -userExtensions argument and pass in your user-extensions.js file.
java -jar selenium-server.jar -userExtensions user-extensions.js