将 Jquery 库添加到 Selenium

发布于 2024-10-01 20:05:26 字数 1033 浏览 1 评论 0原文

有人可以告诉我如何将 Jquery 库添加到 Selenium 吗?我确实在网上进行了搜索,下面是我到目前为止所遵循的步骤。我不知道下一步该做什么。在这些更改之后,如何通过更改重新构建 selenium jar?

  1. 解压 selenium 2.04.jar 将
  2. user-extensions.js 中 jQuery.js 的内容复制
  3. 到 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?

  1. Unzipped selenium 2.04.jar
  2. Copied contents of jQuery.js in user-extensions.js
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2024-10-08 20:05:27

要更新 jar 中的文件,请参阅此处

本质上:

添加文件的基本命令有
这种格式:

jar uf jar-file 输入文件 在此
命令:

u选项表示你想要
更新现有的 JAR 文件。的f
选项表示 JAR 文件
更新是在命令上指定的
线。如果 f 选项不存在,
Jar 工具需要一个 JAR
标准输入上的文件名。 jar 文件是
现有的 JAR 文件
已更新。输入文件是
以空格分隔的一个或多个列表
您想要添加到 Jar 的文件
文件。

您也许还可以将 JQuery js 文件添加为 Selenium 用户扩展。请参阅此处

只需记住使用 -userExtensions 参数启动 Selenium RC 服务器并传入 user-extensions.js 文件。

java -jar selenium-server.jar
-userExtensions user-extensions.js

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文