English 中文(简体)
How to use multiple CSS locators as a selenium locator?
原标题:

I m trying to hit a link in a table-row that contains multiple links. This pattern is used throughout the table.

This works:

browser.wait_for(:element => "css=tr:nth-child(1) li:nth-child(2) > a")

This does not:

browser.click "css=tr:nth-child(1) li:nth-child(2) > a"

Any ideas why this might be? I m using the selenium-client rubygem.

最佳回答

I suspect this is due to a bug in cssQuery, which Selenium currently uses to locate elements by CSS. Details of the issue and a patch can be found in the comments of the following issue: http://jira.openqa.org/browse/SEL-698

Hope that helps - I believe Selenium 2 will be using a different library for CSS locators - possibly JQuery s Sizzle (http://sizzlejs.com/), which should solve this problem.

Dave.

问题回答

To avoid painful CSS issues like this, I ve installed jQuery as a user extension. It gives the ability to define a locator String similar to CSS ("jquery=td.dt-col-status div.dt-liner:contains( Complete )") that is much more powerful. I can expand on how I did it for the Java RC if you d like.

This is a bug in selenium 1 I would try writing out the entire path in your css path and see if that helps.

ex if you are using the following html you can use the following css locator

    <table>
        <tr>
            <td>
                <li>
                    <a href="/yourlink" >
</li> </td> </tr> </table>
"css=tr:nth-child(1) > td > li:nth-child(2) > a"

If that doesn t work you can always use xpath. It s just as expressive as CSS locators but tends to have fewer glitches. The only thing you have to keep in mind when using xpaths is that they are generally slower than css locators.

"xpath=//tr/td//li[2]/a" 




相关问题
Javascript communication with Selenium (RC)

My Application has a lot of calculation being done in JavaScript according to how and when the user acts on the application. The project prints out valuable information (through console calls) as to ...

Running automated Web browser tests under Hudson

I m running Hudson for my automated builds and love it. I d now like to create automated Web browser tests using either WaTiN (preferred) or Selenium. As my Hudson runs as a Windows service (under ...

Using a Java library with Scala reserved words

I m using an external library written in Java (Selenium). One of the function calls has the signature type(String, String), and I keep getting compiler errors when trying to call it from Scala, that ...

Heightened privilege selenium browsers on Windows 7 (x64)

I make use of *firefox and *iexplore etc. within my selenium tests to get around the issue of self-signed SSL certificates on my local machine. Unfortunately, now that I ve moved from XP over to 7, ...

Selenium not working with Firefox 3.x on linux

I am using selenium-server , selenium rc for UI testing in my application . My dev box is Windows with FireFox 3.5 and every thing is running fine and cool. But when i try to run selenium tests on my ...

Selenium IDE: Incrementing values by 1 and 71

Currently I m incrementing a value called wert by 1 with the following code: getEval storedVars[ wert ]=${wert}+1; The value wert is something like 80401299. I want to add 1 to the value, if it ...

热门标签