【问题标题】:Finding a specific pattern using regex in xpath在 xpath 中使用正则表达式查找特定模式
【发布时间】:2020-12-04 19:08:32
【问题描述】:

我想在 xpath 中使用正则表达式查找特定文本。

这是我的 xpath:

locator: //*[@class = 'android.widget.TextView' and contains(@text,'PriceBottomBarDialog-selector')]

这个“PriceBottomBarDialog-selector”保持不变,开始的文字不断变化。任何人都可以帮助使用正则表达式模式吗?

谢谢

【问题讨论】:

    标签: java selenium xpath xpath-1.0


    【解决方案1】:

    你很亲密。你需要修复,你可以使用Locator Strategy

    • Xpath:

      locator: //*[@class = 'android.widget.TextView' and contains(.,'PriceBottomBarDialog-selector')]
      

    【讨论】:

    • 其实就是content-desc“item-Jet item-PriceBottomBarDialog-selector”。任何想法如何实现这一点。 “PriceBottomBarDialog-selector”保持不变。
    • @Piku 如果我正确理解了你的问题,如果是content-desc="item-Jet item-PriceBottomBarDialog-selector",你可以这样做contains(@content-desc,'PriceBottomBarDialog-selector')
    • 嗨@DebsnjanB 它没有给我正确的输出,它给我一个错误,说找不到元素。
    • @Piku 这个答案是为了满足您对 regex 模式 的要求。要解决element not found,您能否根据您的新要求提出一个新问题?
    猜你喜欢
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    相关资源
    最近更新 更多