【问题标题】:How can I select an element with a specific `title` using selenium in python如何在 python 中使用 selenium 选择具有特定“标题”的元素
【发布时间】:2020-05-26 22:04:08
【问题描述】:

如何使用 selenium 获取具有特定属性的项目并单击它?在我的情况下,一个带有“商店类型”的title。我尝试了 XPath 和许多其他方法,但仍然无法做到这一点。

以下是描述问题的示例图像

【问题讨论】:

  • 这不是问题
  • 这是什么东西。
  • 请分享您正在使用的代码
  • 除非绝对必要,否则请不要将信息共享为图像。请参阅:meta.stackoverflow.com/questions/303812/…
  • 我尝试过 XPath 和许多其他方法我们需要看看这些尝试。

标签: python html selenium xpath


【解决方案1】:

你可以通过xpath获取元素:

//div[@title="Store Type"]

如果我没记错python是:

driver.find_element_by_xpath('//div[@title="Store Type"]').click()

【讨论】:

    【解决方案2】:

    你可以使用xpath点击元素:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@title='Store Type']"))).click()
    

    注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

    【讨论】:

      猜你喜欢
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 2018-05-19
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      相关资源
      最近更新 更多