【问题标题】:Unable to find element in IE but in FF it works fine无法在 IE 中找到元素,但在 FF 中可以正常工作
【发布时间】:2013-02-06 22:46:46
【问题描述】:

编辑:

我的 CSSSelector 是这样的:(在 FF 中运行良好)

for (int i = 1; i < _count; i++)
{
    ..................
    ..................
    div#ctl00_ContentPlaceHolder1 table.gv tbody tr.item:nth-child(" + i + ") > td:nth-of-type(3)
    ..................

}

编辑结束

我正在使用 Selenium 2.29 和 IE (8) 和 FF (17.1) 在 FF 中,我所有的测试用例都通过了,当我在 IE 中运行时,我的大多数测试用例都失败了,这是错误消息:

Test method threw exception: 
OpenQA.Selenium.WebDriverTimeoutException: Timed out after 30 seconds ---> OpenQA.Selenium.NoSuchElementException: 
Unable to find element with css selector == 

div#ctl00_ContentPlaceHolder1 table.gv tbody tr.item:nth-child(1) > td:nth-of-type(3)

我正在使用 CSSSelector。

我是否必须更改 CSSSelector 才能使 IE 工作?

【问题讨论】:

    标签: selenium css-selectors selenium-webdriver xpath


    【解决方案1】:

    根据:http://www.quirksmode.org/css/contents.html#t38

    IE8 及以下不支持:nth 选择器。

    【讨论】:

    • 那么我的问题的解决方案是什么?
    • 将您的 CSS 选择器更改为其他值,或使用 XPath。或者注入 Sizzle 以将其用于 CSS 而不是原生 CSS 支持。
    【解决方案2】:

    IE8 不支持 CSS nth-of-type

    【讨论】:

      【解决方案3】:

      由于 IE8 不支持 :nth 选择器,请尝试注入 Sizzle。 Sizzle(jQuery 使用的选择器引擎)带有内置的 :nth-child() 选择器,但缺少 :nth-of-type() 选择器。尝试用:nth-child替换你的:nth-of-type

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-20
        相关资源
        最近更新 更多