将 Jquery 库添加到 Selenium
有人可以告诉我如何将 Jquery 库添加到 Selenium 吗?我确实在网上进行了搜索,下面是我到目前为止所遵循的步骤。我不知道下一步该做什么。在这些更改之后,如何通过更改重新构建 selenium jar?
- 解压 selenium 2.04.jar 将
- user-extensions.js 中 jQuery.js 的内容复制
- 到 selenium-remoterunner.js 文件的 runSeleniumTest() 函数中的 Selenium 核心,如下所示,
函数runSeleniumTest() { ... selenium.doAddLocationStrategy("jquery", " var loc = 定位器; var attr = null; var isattr = false; var inx = locator.lastIndexOf('@');
if (inx != -1) { loc = locator.substring(0, inx); attr = locator.substring(inx + 1); isattr = 真 } var 选择器 = loc.split('<'); var 找到 = $(inDocument); for (var i = 0; i < 选择器.length; i++) { if (i > 0) {found = $(found.parents()[0]); } if (jQuery.trim(selectors[i]) != '') 找到 = 找到.find(选择器[i]); } if (found.length > 0) { 如果(isattr){ 返回找到[0].getAttributeNode(attr); } 别的 { 返回找到的[0]; } } 别的 { 返回空值; } ”); ... }
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; } "); ... }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要更新 jar 中的文件,请参阅此处。
本质上:
您也许还可以将 JQuery js 文件添加为 Selenium 用户扩展。请参阅此处。
只需记住使用 -userExtensions 参数启动 Selenium RC 服务器并传入 user-extensions.js 文件。
To update a file in a jar, refer here.
Essentially:
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.