【问题标题】:how to use operator " in " in xpathin selenium如何在 xpathin selenium 中使用运算符“in”
【发布时间】:2019-02-22 11:17:41
【问题描述】:

if link : l = link.get_attribute("href") print (l) button=self.driver.find_element_by_xpath( "//button[@id = 'refuse-alert-button' and @data-record " in l +"]")

bug ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// \frontend.py",第 233 行,在reject_record "//button[@id = 'refuse-alert-button' and @data-record "in l +"]")

【问题讨论】:

  • 这听起来像是X-Y problem。与其寻求解决问题的帮助,不如编辑您的问题并询问实际问题。你想做什么?
  • 请尝试更合理地格式化您的问题。
  • XPath "in" operator的可能重复
  • ^ 根据链接的问题,in 运算符在 XPath 2.0 中可用。 Selenium 仅支持 XPath 1.0。可能还有另一种方法可以做到这一点。请编辑您的问题并添加更多详细信息,例如相关的 HTML 以及您要完成的任务。

标签: python selenium xpath


【解决方案1】:

我的理解是你想要获取与你想要在 xpath 中传递的属性匹配的元素。

//button[@id = 'refuse-alert-button' and @data-record ='" + l + "']

l = link.get_attribute("href") 
    print (l)  
button=self.driver.find_element_by_xpath( "//button[@id = 'refuse-alert-button' and @data-record ='" + l + "']")

你的情况

如果想要部分匹配,您可以使用contains

//button[@id = 'refuse-alert-button' and contains(@data-record,'" + l + "')]

【讨论】:

    猜你喜欢
    • 2018-09-16
    • 2022-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多