绝对 xpath 和相对 xpath 有什么区别?在 Selenium 自动化测试中哪个是首选? [英] What is the difference between absolute and relative xpaths? Which is preferred in Selenium automation testing?

查看:23
本文介绍了绝对 xpath 和相对 xpath 有什么区别?在 Selenium 自动化测试中哪个是首选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绝对 xpath 和相对 xpath 有什么区别?在 Selenium 自动化测试中哪个是首选?我正在准备使用 Selenium 和 Robot 框架的测试脚本.

What is the difference between absolute and relative xpaths? Which is preferred in Selenium automation testing? I am preparing test scripts using Selenium and Robot framework.

推荐答案

Absolute Xpath:它使用从根元素到所需元素的完整路径.

Absolute Xpath: It uses Complete path from the Root Element to the desire element.

相对 Xpath:您可以简单地从引用您想要的元素开始,然后从那里开始.

Relative Xpath: You can simply start by referencing the element you want and go from there.

相对 Xpath 总是首选,因为它们不是来自根元素的完整路径.(//html//正文).因为将来,如果添加/删除任何 webelement,那么绝对 Xpath 会发生变化.因此,请始终在自动化中使用相对 Xpath.

Relative Xpaths are always preferred as they are not the complete paths from the root element. (//html//body). Because in future, if any webelement is added/removed, then the absolute Xpath changes. So Always use Relative Xpaths in your Automation.

以下是一些链接,您可以参考这些链接以获取有关它们的更多信息.

Below are Some Links which you can Refer for more Information on them.

这篇关于绝对 xpath 和相对 xpath 有什么区别?在 Selenium 自动化测试中哪个是首选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆