开发者

Optimization in XPath

开发者 https://www.devze.com 2023-04-11 08:57 出处:网络
I\'m doing some Selenium tests now and I have code like this: Assert.IsTrue(selenium.IsElementPresent(\"//div[text()=\'RSS Feed\']\"));

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) a开发者_如何学编程ffects the speed of program and lowers time required to find an element on page?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消