【问题标题】:Locating specific elements on selenium or checking multiple things on a single element- Python 3在 selenium 上定位特定元素或在单个元素上检查多个事物 - Python 3
【发布时间】:2017-06-16 05:03:38
【问题描述】:

假设我有这个代码:

<li attrib1="attrib1_text" attrib2="attrib2_text" another_attrib = "sometext"> ...
 </li>

我想找到 attrib1 属性和 attrib2 属性,如果正确则返回 true,例如

if attrib1 == "attrib1_text" and attrib2 == "attrib2_text":
    return true

我尝试过这样的事情:

domain_test = '//*[contains(@attrib1, "attrib1_text" and @attrib2, "attrib2_text")]'
driver = webdriver.Chrome()
try:
   elem = driver.find_element_by_xpath(domain_test)
   return True
except NoSuchElementException:
   return False

但是,当它应该返回 True 时,它​​返回 False

【问题讨论】:

  • 可以分享一下网站吗?

标签: python python-3.x selenium


【解决方案1】:

尝试简单地替换这个谓词

[contains(@attrib1, "attrib1_text" and @attrib2, "attrib2_text")]

有了这个

[contains(@attrib1, "attrib1_text") and contains(@attrib2, "attrib2_text")]

或者这个

[@attrib1="attrib1_text" and @attrib2="attrib2_text"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2015-08-15
    • 2019-01-08
    相关资源
    最近更新 更多