问题
I am testing an application using Selenium IDE. There is a table with unstable row ordering - which means the elements I need to verify are in different rows on each test run.
I'd like to use text known to be in the first column to find the row; and then verify the other columns in the same row.
The test looks like this:
store || //form/table || tableXpath
store || 3 || initialsRow
verifyTable || ${tableXpath}.${initialsRow}.0 || Initials
verifyTable || ${tableXpath}.${initialsRow}.1 || MJ
verifyTable || ${tableXpath}.${initialsRow}.2 || MH
Instead of hard-coding the "initialsRow" value; is it not possible to find the row index dynamically?
回答1:
The solution I found was to use the Selenium's storeElementIndex
command. It gets the index of an HTML element relative to its parent.
See http://release.seleniumhq.org/selenium-core/1.0.1/reference.html
I changed the test as follows:
store || //form/table || tableXpath
storeElementIndex || ${tableXpath}//tr/td[text() = "Initials"]/.. || initialsRow
verifyTable || ${tableXpath}.${initialsRow}.1 || MJ
verifyTable || ${tableXpath}.${initialsRow}.2 || MH
The XPath query //form/table//tr/td[text() = "Initials"]/..
finds the 'tr' element above the 'td' element containing the text "Initials". Selenium stores the index of this 'tr' element relative to whatever its parent element is.
回答2:
Well, now I found, selenium CAN calculate. Unfortunately not implicitly like ${tableXpath}.${initialsRow + 1}.1
.
So I added an additional command:
storeEval || ${ORBInitialPort} + 1 || ORBInitialPortRow
and used ORBInitialPortRow
instead of ORBInitialPort
as index.
来源:https://stackoverflow.com/questions/11051457/selenium-ide-can-i-select-a-row-based-on-column-content-to-verify-other-column