Tellurium Tutorial Series: What is wrong with Selenium XPath

18 views
Skip to first unread message

John.Ji...@gmail.com

unread,
Oct 19, 2008, 12:36:19 AM10/19/08
to tellurium-users
One user in Selenium RC forum asked me "what is wrong with Selenium
XPath?"
My answer is that the problem is not in XPath itself, but the way
Selenium uses it.

First, the XPath in Selenium is fixed once it is generated. Usually,
Selenium IDE or
XPather created the XPath like

"//div/table[@id='something']/div[2]/div[3]/div[1]/div[6]"

See any problem with that? It is not robust. Along the path
div -> table -> div -> div ->div -> div, if anything is changed
there, your XPath is no longer valid. For example, if you add
additional UI elements
and the new XPath is changed to

"//div[2]/table[@id='something']/div[3]/div[3]/div[1]/div[6]"

You have to keep updating the XPaths for all its descendant UI
objects. For Tellurium,
the runtime XPath is generated by walking through the nested UI
objects. The XPath
is generated from element attributes for composite locator and even
for base locator,
the XPath is also generated from a set of relative XPaths. This also
means that if we
change one UI object, the rest UI objects do not need to be changed.
As a result,
Tellurium can be adaptive to changes to some degree.

More importantly, Tellurium uses the group locating concept to use
information from
a group of UI elements to locate them in the DOM. In most cases, the
group of elements
themselves can be enough to decide their locations in the DOM, that is
to say, your UI
element's location does not depend on its parent or grandparent
elements.
For example, in the above example, if you can use the group locating
concept to find
locators for the following part of UI elements,

"div[3]/div[1]/div[6]"

directly, then they do not depend on the portion "div[2]/
table[@id='something']/div[3]",
certainly. your UI elements can address any changes in the portion of
"div[2]/table[@id='something']/div[3]".

Secondly, The syntax of XPath

selenium.type("//input[@title='Google Search']", input)
selenium.click("//input[@name='btnG' and @type='submit']")
...
selenium.type("//input[@title='Google Search']", input)
selenium.click("//input[@name='btnG' and @type='submit']")
...
selenium.type("//input[@title='Google Search']", input)
selenium.click("//input[@name='btnG' and @type='submit']")
...


in everywhere is really ugly to users. Especially if someone needs to
take over your code.
In Tellurium, the UiID is used and it is very clear to users what you
are acting on.

click "google_start_page.googlesearch"
Reply all
Reply to author
Forward
0 new messages