【问题标题】:How to locate 2 text with same xpath?如何找到具有相同 xpath 的 2 个文本?
【发布时间】:2020-03-10 08:59:03
【问题描述】:

如何在同一个 xpath 中定位文本? 我用过但不工作:

//div[contains(text(),"Review") and contains(text(),"received"]

【问题讨论】:

  • You are missig the close ')' --> //div[contains(text(),"Review") and contains(text(),"received")]

标签: python frameworks robot


【解决方案1】:

文本属于两个不同的标签。您可以查找带有"Review" 文本的元素,该元素有一个带有"received" 文本的子元素

//div[contains(text(),"Review") and div[contains(text(),"received")]]

【讨论】:

    【解决方案2】:

    保重,你离任务越近')'

    //div[contains(text(),"Review") and contains(text(),"received")]
    

    但这不是好的 xpath,因为“received”在内部元素上

    试试这个,.//* 表示任何子元素,可以在第二个包含时使用 ./div

    //div[.//*[contains(text(),"Review")] and .//*[contains(text(),"received")]]
    

    //div[contains(text(),"Review") and .//*[contains(text(),"received")]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-11
      • 2016-12-26
      • 2019-11-24
      相关资源
      最近更新 更多