XPath中的优化
我现在正在做一些Selenium测试,代码如下:XPath中的优化,xpath,selenium,Xpath,Selenium,我现在正在做一些Selenium测试,代码如下: Assert.IsTrue(selenium.IsElementPresent("//div[text()='RSS Feed']")); Assert.IsTrue(selenium.IsElementPresent("//div[@id='btnLogout_Container']")); 我将其替换为以下内容: Assert.IsTrue(selenium.IsElementPresent("//div/dl/dt/a/div[text(
Assert.IsTrue(selenium.IsElementPresent("//div[text()='RSS Feed']"));
Assert.IsTrue(selenium.IsElementPresent("//div[@id='btnLogout_Container']"));
我将其替换为以下内容:
Assert.IsTrue(selenium.IsElementPresent("//div/dl/dt/a/div[text()='RSS Feed']"));
Assert.IsTrue(selenium.IsElementPresent("//tbody/tr/td/div[@id='btnLogout_Container']"));
然后我运行了一些测试并计时-结果是相同的,差异仅在0.001秒内。所以我想知道,这种改变(为XPath添加更详细的方式)是否会影响程序的速度并减少在页面上查找元素所需的时间?这取决于XPath处理器和许多其他您没有告诉我们的事情。例如,如果您的源文档很小,那么编译XPath表达式将比执行XPath表达式花费更长的时间。这取决于XPath处理器以及您没有告诉我们的许多其他事情。例如,如果源文档很小,那么编译XPath表达式将比执行它花费更长的时间