Difference between revisions of "Testing: Selenium: ZimbraSelenium Tips"

 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==General Information==
+
{{Archive}}==General Information==
  
 
This page details some helpful tips regarding usage of the Zimbra Selenium Harness
 
This page details some helpful tips regarding usage of the Zimbra Selenium Harness
Line 11: Line 11:
 
Using the most optimal locators is crucial for cross-browser compatibility.  IE is notoriously slow for processing xpath locators.  As per the [http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.html Selenium documentation], the preferred format of locators is:
 
Using the most optimal locators is crucial for cross-browser compatibility.  IE is notoriously slow for processing xpath locators.  As per the [http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.html Selenium documentation], the preferred format of locators is:
  
# by Identifier (i.e. locator="DWT233")
 
 
# by CSS (i.e. locator="css=a[href='#id3']")
 
# by CSS (i.e. locator="css=a[href='#id3']")
 
# by xpath (i.e. locator="//a(@href='@id3']")
 
# by xpath (i.e. locator="//a(@href='@id3']")
 +
# by Identifier (i.e. locator="DWT233")
  
 
=====Translation: xpath to css=====
 
=====Translation: xpath to css=====
 +
 +
For those familiar with xpath but not css, here are some tips for translation.
  
 
{| class="wikitable" style="width: 80%; text-align: center; border: 1px solid blue;" border="1"
 
{| class="wikitable" style="width: 80%; text-align: center; border: 1px solid blue;" border="1"
Line 22: Line 24:
 
! css
 
! css
 
! preferred
 
! preferred
! usage
+
! description
 +
|-
 +
| "xpath=//div[@id='foo']" || "css=div#foo" || "css=div#foo" || div with id equals "foo"
 +
|-
 +
| "xpath=//div[@class='bar']" || "css=div.bar" || "css=div.bar" || div with class attribute equals "bar"
 +
|-
 +
| "xpath=//div[@id='foo' and @class='bar']" || "css=div#foo.bar" || "css=div#foo.bar" || div with id=foo and class attribute equals "bar"
 +
|-
 +
| "xpath=//tr[contains(@attr,'partial']" || "css=tr[attr*='foo']" || "css=tr[attr*='foo']" || attr contains foo
 +
|-
 +
| - || "css=tr[attr^='foo']" || "css=tr[attr^='foo']" || attribute starts with foo
 +
|-
 +
| - || "css=tr[attr$='foo']" || "css=tr[attr$='foo']" || attribute ends with foo
 +
|-
 +
| xpath=(//div[@id='foo'])@class || "css=div[id='foo']@class" || sGetAttribute("css=div[id='foo']@class") || CSS format for sGetAttribute()
 
|-
 
|-
| "xpath=//div[@id='foo']" || "css=div[id='foo']" || "foo" || sIsElementPresent("foo")
+
| xpath=//div//table || "css=div table" || "css=div table" || descendant
 
|-
 
|-
| "xpath=//tr[contains(@attr,'partial']" || "css=tr[attr*='foo']" || "css=tr[attr*='foo']" || sIsElementPresent("css=tr[attr*='foo']")
+
| xpath=//div/table || "css=div>table" || "css=div>table" || child
 
|}
 
|}
  
 
+
==Links==
  
 
See http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/
 
See http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/
Line 35: Line 51:
 
See http://saucelabs.com/blog/index.php/2010/03/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/
 
See http://saucelabs.com/blog/index.php/2010/03/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/
  
 
+
See http://www.ivaturi.org/home/hackingseleniumtoimproveitsperformanceonie
  
  

Latest revision as of 17:25, 25 March 2015

General Information

This page details some helpful tips regarding usage of the Zimbra Selenium Harness

Code

Selenium

Preferred Locator Formats

Using the most optimal locators is crucial for cross-browser compatibility. IE is notoriously slow for processing xpath locators. As per the Selenium documentation, the preferred format of locators is:

  1. by CSS (i.e. locator="css=a[href='#id3']")
  2. by xpath (i.e. locator="//a(@href='@id3']")
  3. by Identifier (i.e. locator="DWT233")
Translation: xpath to css

For those familiar with xpath but not css, here are some tips for translation.

xpath css preferred description
"xpath=//div[@id='foo']" "css=div#foo" "css=div#foo" div with id equals "foo"
"xpath=//div[@class='bar']" "css=div.bar" "css=div.bar" div with class attribute equals "bar"
"xpath=//div[@id='foo' and @class='bar']" "css=div#foo.bar" "css=div#foo.bar" div with id=foo and class attribute equals "bar"
"xpath=//tr[contains(@attr,'partial']" "css=tr[attr*='foo']" "css=tr[attr*='foo']" attr contains foo
- "css=tr[attr^='foo']" "css=tr[attr^='foo']" attribute starts with foo
- "css=tr[attr$='foo']" "css=tr[attr$='foo']" attribute ends with foo
xpath=(//div[@id='foo'])@class "css=div[id='foo']@class" sGetAttribute("css=div[id='foo']@class") CSS format for sGetAttribute()
xpath=//div//table "css=div table" "css=div table" descendant
xpath=//div/table "css=div>table" "css=div>table" child

Links

See http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/

See http://saucelabs.com/blog/index.php/2010/03/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class/

See http://www.ivaturi.org/home/hackingseleniumtoimproveitsperformanceonie


Verified Against: unknown Date Created: 11/7/2007
Article ID: https://wiki.zimbra.com/index.php?title=Testing:_Selenium:_ZimbraSelenium_Tips Date Modified: 2015-03-25



Try Zimbra

Try Zimbra Collaboration with a 60-day free trial.
Get it now »

Want to get involved?

You can contribute in the Community, Wiki, Code, or development of Zimlets.
Find out more. »

Looking for a Video?

Visit our YouTube channel to get the latest webinars, technology news, product overviews, and so much more.
Go to the YouTube channel »

Jump to: navigation, search