QA/Execution/Web Testing/Selenium Guidelines: Difference between revisions
< QA | Execution | Web Testing
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 9: | Line 9: | ||
* Locating elements | * Locating elements | ||
** xpath: for elements that have dynamically generated xpaths use 'contains'. | ** xpath: for elements that have dynamically generated xpaths use 'contains'. | ||
for e.g. if xpath for 'remove add-on' link has the add-on ID | for e.g. if xpath for 'remove add-on' link has the add-on ID | ||
in it (id('addon-2464')/a[1]) and we do not know the add-on ID then | in it (id('addon-2464')/a[1]) and we do not know the add-on ID then | ||
we can write the xpath with 'contains' | we can write the xpath with 'contains' | ||
//div[@id,'addon-2464'][2]/a[1]) => //div[contains(@id,'addon- ')][2]/a[1] | //div[@id,'addon-2464'][2]/a[1]) => //div[contains(@id,'addon- ')][2]/a[1] | ||
** If you want to match on the text in an element | ** If you want to match on the text in an element | ||
//a[text()=’My Text’]: matches a link whose text is “My Text” | //a[text()=’My Text’]: matches a link whose text is “My Text” | ||
** If you want to match more than one string in attribute or text | ** If you want to match more than one string in attribute or text | ||
//a[contains(text(),’Bill’) && contains(text(), ‘Clinton’)]: matches a link whose text contains both Bill and Clinton. You can use any xpath function or operator to create your expression | //a[contains(text(),’Bill’) && contains(text(), ‘Clinton’)]:matches a link whose text contains both Bill and Clinton. You can use any xpath function or operator to create your expression | ||
** Find the nth element of a type | ** Find the nth element of a type | ||
//div[position()=3]: matches the third div on the page | //div[position()=3]: matches the third div on the page | ||
//div[@id=’abc’]//table[position()=3]: matches the third table inside the div whose id is abc | //div[@id=’abc’]//table[position()=3]: matches the third table inside the div whose id is abc | ||
Revision as of 23:42, 23 October 2009
Here be some Selenium guidelines (mostly for writing, but include running here too).
IDE
- click vs. clickAndWait - use the latter on anything that requires network activity, but if you use the former on other buttons/links, your script will pause indefinitely
- verifyLocation - use w/regexp; otherwise it'll be absolute (I think)
- e.g. ...
- wherever possible, use relative--not absolute--URLs in |open| commands
PHP
- Locating elements
- xpath: for elements that have dynamically generated xpaths use 'contains'.
for e.g. if xpath for 'remove add-on' link has the add-on ID
in it (id('addon-2464')/a[1]) and we do not know the add-on ID then
we can write the xpath with 'contains'
//div[@id,'addon-2464'][2]/a[1]) => //div[contains(@id,'addon- ')][2]/a[1]
- If you want to match on the text in an element
//a[text()=’My Text’]: matches a link whose text is “My Text”
- If you want to match more than one string in attribute or text
//a[contains(text(),’Bill’) && contains(text(), ‘Clinton’)]:matches a link whose text contains both Bill and Clinton. You can use any xpath function or operator to create your expression
- Find the nth element of a type
//div[position()=3]: matches the third div on the page //div[@id=’abc’]//table[position()=3]: matches the third table inside the div whose id is abc