Selenium IDE - Can I select a row based on column content to verify other columns?

只愿长相守 提交于 2019-12-06 05:34:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!