c# - Jquery 在 selenium 中找不到元素

标签 c# jquery python selenium selenium-rc

 sel.add_script( sel.get_location(), "jquery.js")

 #here I get  u'fd6c42bcc770ca9decc4f358df3688290a4257ad'`  
       idOfResultWithSomeImage=sel.get_eval("window.jQuery('#result').find('img').filter('[alt=SeleImage]').eq(0).parents('form:first').find('a').eq(1).attr('id')")`

    #here I get u"window.jQuery('#fd6c42bcc770ca9decc4f358df3688290a4257ad').parent().find('button')"
        pathOfButton="window.jQuery('#" + idOfResultWithSomeImage+ "').parent().find('button')"

        #here I get false :/ 
        isButtonPreset = sel.is_element_present(pathOfButton)
        #so here I get error. Element not present.
        sel.click(pathOfButton)

当我在 firebug 的控制台中检查它时,它找到了这个按钮。

我在用

# -*- coding: utf-8 -*-

而且我在 WingIde 中编码。

你知道这是为什么吗?

编辑

#from here I get 08f0ddbfa71df43bee87d9becdec5ced4ead3419
idOfResultWithRyanairFlight=sel.get_eval("window.jQuery('#result').find('img').filter('[alt=Ryanair]').eq(0).parents('form:first').find('a').eq(1).attr('id')")

我在 Debug模式下检查并:

#it returns true
sel.is_element_present("css=#08f0ddbfa71df43bee87d9becdec5ced4ead3419")
#it returns false
sel.is_element_present("window.jQuery('#08f0ddbfa71df43bee87d9becdec5ced4ead3419')")
#it return false
sel.is_element_present("window.jQuery(#08f0ddbfa71df43bee87d9becdec5ced4ead3419)")

我将此查询放在 Firebug 控制台中,然后进行第一和第二项工作。

编辑

有趣的是,我用 C# 编写了相同的脚本,但我遇到了同样的问题。

 var dOfA = selenium.GetEval("window.jQuery('#result').find('img').filter('[alt=SomeIMG]').eq(0).parents('form:first').find('a').eq(1).attr('id')");


            var a=selenium.IsElementPresent("window.jQuery('#" + dOfA + "').parent().find('button')");
            var b = selenium.IsElementPresent("$('#" + dOfA + "')");
            var c = selenium.IsElementPresent("jQuery('#" + dOfA + "')");
            var d = selenium.IsElementPresent("css=#" + dOfA);
            var e = selenium.GetEval("window.jQuery('#" + dOfA + "')");

只有 d 为真。

最佳答案

如果您想在 Selenium 中使用 CSS/jQuery 样式选择器,我认为您必须一直使用 CSS 选择器。换句话说,你需要这样的东西:

pathOfButton = "css=#" + idOfResultWithSomeImage + " ~ button"
if (!sel.is_element_present(pathOfButton))
    pathOfButton = "css=button ~ #" + idOfResultWithSomeImage

sel.click(pathOfButton)

可能有更好的方法来做到这一点;另外,我没有用 python 编程,所以我的语法可能不对。

参见 this Selenium documentation page获取更多定位器信息。

关于c# - Jquery 在 selenium 中找不到元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4347346/

相关文章:

c# - Windows 服务无法创建文本文件

python - 如何在 Jupyter Notebook 的单个单元格中的多个 print() 命令的结果之间添加行距?

python - Scapy加载到可读字符串python 3.7

python - 如何根据 Pandas 数据框中的列值(int)合并行(带有字符串)?

c# - 模拟企业 Lib 5 'Database'

c# - 如何在无限循环中使用线程锁?

c# - 具有公共(public)权限的 Amazon S3 上传

jquery - 不要在移动设备中使用 Bootstrap 显示响应段落

javascript - 在 Javascript 中将行追加到表中

javascript - 两个委托(delegate)函数中只有一个起作用