简体   繁体   English

如何编写相对路径表达式(XPath)以从以下屏幕截图中提取Card Details?

[英]How to write the relative path expression (XPath) to extract the Card Details from the following screenshot?

This is the image from google chrome 这是来自谷歌浏览器的图片

Hi All, 大家好,

I am trying to write the relative expression(XPath) to get the card details from the following website 我正在尝试编写相对表达式(XPath),以从以下网站获取卡的详细信息

https://www.fakenamegenerator.com/gen-random-us-us.php https://www.fakenamegenerator.com/gen-random-us-us.php

I see that the card name keeps alternating between VISA and MasterCard, 我看到卡名在VISA和万事达卡之间不断变化,

I wanted to know if the following expression is possible 我想知道以下表达式是否可能

" //dl[dt/text()='MasterCard']/dd OR //dl[dt/text()='Visa']/dd " // dl [dt / text()='MasterCard'] / dd或// dl [dt / text()='Visa'] / dd

Can I use OR operator to make the expression generic so that it will work for both the cases VISA or Master Card? 我可以使用OR运算符来使表达式通用,以便它既适用于VISA还是适用于万事达卡?

FYI this is for an Automation Anywhere project where I am practicing to enhance my skills in WEB Automations 仅供参考,这是我正在练习的自动化Anywhere项目,旨在增强我在WEB自动化方面的技能

You were close, but you cannot use the or operator like that. 您已经很亲密,但是不能像这样使用or运算符。 It is used when you want to have multiple predicate conditions. 当您要具有多个谓词条件时使用它。 If you would like to have multiple possible node results (like in your example), you would use a pipe | 如果您希望有多个可能的节点结果(如您的示例中所示),则可以使用管道| operator 操作者

  1. //dl[dt/text()='MasterCard']/dd | //dl[dt/text()='Visa']/dd
  2. //dl[dt/text()='MasterCard' or dt/text()='Visa']/dd
  3. //dl[dt[text()='MasterCard' or text()='Visa']]/dd

The first option says: 第一个选项说:
Get me a dd element that is a direct child of a dl element with a dt element with text 'MasterCard' 给我一个dd元素,它是dl元素的直接子元素,而dt元素的文本为'MasterCard'
OR 要么
a dd element that is a direct child of a dl element with a dt element with text 'Visa'. dd元素,它是dl元素的直接子元素,而dt元素的文本为“ Visa”。

The second option says: 第二个选项说:
Get me a dd element that is a direct child of a dl element with a dt element with text 'MasterCard' OR 'Visa'. 给我一个dd元素,它是dl元素的直接子元素,而dt元素是文本“ MasterCard” “ Visa”。

The third option is just a slightly more compact version of the second one. 第三种选择只是第二种选择的紧凑形式。

So while both options will give you the same results (in this case), the performance may be very different. 因此,尽管这两个选项都会为您提供相同的结果(在这种情况下),但性能可能会非常不同。 Using the pipe operator basically means that you are doing multiple searches rather than a single complex one. 使用管道运算符基本上意味着您要进行多个搜索,而不是单个复杂的搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM