如何在Katalon Studio中使用Xpath 2.0

huangapple 未分类评论44阅读模式
英文:

How uses Xpath 2.0 in Katalon Studio

问题

Sure, here is the translation:

我想知道如何在Katalon Studio中使用XPath 2.0查询?我需要使用ends-with匹配。我发现我尝试使用过的任何浏览器(包括Chrome,Firefox,Edge和IE)都不支持XPath 2.0查询。在这种情况下,我如何在Web测试中使用这些查询?

英文:

I want to know how can I use the XPath 2.0 queries in Katalon Studio? I need to use an ends-with match. I found out that any browsers that I have tried to use (including Chrome, Firefox, Edge, and IE) do not support XPath 2.0 queries. This way, how can I use those queries on a web test?

答案1

得分: 0

我认为 Katalon Studio 不支持 XPath 2.0 表达式(比如 ends-with 函数)。
但你有替代方案。假设你想选择下面的元素:

<div id="foo_bar">我喜欢stackoverflow</div>

如果你想通过属性来定位它,可以使用 CSS 选择器:

div[id$='_bar']

选择一个带有以“_bar”结尾的 id 属性的 div 元素。

如果你想通过内容来定位元素,可以使用以下 XPath(1.0):

//div[substring(.,string-length(.)-string-length('stackoverflow')+1)="stackoverflow"]

选择一个内容以“stackoverflow”结尾的 div 元素。

将来如果你需要测试你的 XPath 1.0/2.0 表达式,你可以使用以下网络服务:

英文:

I don't think Katalon Studio supports XPath 2.0 expressions (like ends-with function).
But you have alternatives. Assuming you want to select the following element :

&lt;div id=&quot;foo_bar&quot;&gt;I love stackoverflow&lt;/div&gt;

If you want to target it with its attribute, use a CSS selector :

div[id$=&#39;_bar&#39;]

Select a div element whith an id attribute which ends ($=) with "_bar"

If you want to target the element with its content, use the following XPath (1.0) :

//div[substring(.,string-length(.)-string-length(&#39;stackoverflow&#39;)+1)=&quot;stackoverflow&quot;]

Select a div element with content ending with "stackoverflow".

In the future, if you need to test your XPath 1.0/2.0 expressions, you can use the following webservices :

huangapple
  • 本文由 发表于 2020年7月25日 04:10:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/63080789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定