Armaxis
Armaxis

Reputation: 161

Optimization in XPath

I'm doing some Selenium tests now and I have code like this:

Assert.IsTrue(selenium.IsElementPresent("//div[text()='RSS Feed']"));
Assert.IsTrue(selenium.IsElementPresent("//div[@id='btnLogout_Container']"));

i've replaced it with this:

Assert.IsTrue(selenium.IsElementPresent("//div/dl/dt/a/div[text()='RSS Feed']"));
Assert.IsTrue(selenium.IsElementPresent("//tbody/tr/td/div[@id='btnLogout_Container']"));

Then I ran some testes and timed it - results were the same, difference was only in 0.001 second. So I wonder, does this changing (adding a more detailed way to XPath) affects the speed of program and lowers time required to find an element on page?

Upvotes: 1

Views: 616

Answers (1)

Michael Kay
Michael Kay

Reputation: 163282

It depends on the XPath processor and on many other things that you have told us nothing about. If your source document is small, for example, compiling the XPath expression will take much longer than executing it.

Upvotes: 1

Related Questions