简体   繁体   English

如何在python中使用selenium选择具有特定`title`的元素

[英]How can I select an element with a specific `title` using selenium in python

How can I get an item with a specific attribute using selenium and click on it?如何使用 selenium 获取具有特定属性的项目并单击它? In my case one with a title of "Store Type".在我的例子中, title为“商店类型”。 I've tried XPath and many other ways, but still can't do this.我已经尝试过 XPath 和许多其他方法,但仍然无法做到这一点。

The following is an example image depicting the problem以下是描述问题的示例图像

页面标记

You can get element by xpath:您可以通过 xpath 获取元素:

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

If I'm not mistaken in python is:如果我在 python 中没有弄错的话是:

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

You can click on the element using xpath:您可以使用 xpath 单击元素:

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

Note: You have to add the following imports :注意:您必须添加以下导入:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium 和 Python 来 select 一个没有标题的元素? - How to select an element with no title using Selenium and Python? 如何使用 Selenium 和 Python 识别具有特定文本和特定标题的元素 - How to identify an element with a specific text and a specific title using Selenium and Python 当页面上有这么多元素时,我如何 select 页面上的特定元素? Selenium webdriver python; - How can I select a specific element on a page when there is so many of that element? Selenium webdriver python; 我如何单击 selenium python 中列表的特定类别元素 - How can i click specific category element of list in selenium python 如何在 python 中的 selenium 中获取此特定元素 - How can I get this SPECIFIC element in selenium in python 如何通过Selenium Webdriver Python选择“排序依据”元素 - How can I select the “Sort By” element through Selenium Webdriver Python 如何使用 python 和 selenium 为网络爬虫找到对列表中特定元素的引用,该元素的长度定期变化 - How can I find reference to a specific element in a list that changes in length regularly using python and selenium for a webscraper 如何使用Python Selenium选择表中的元素? - How do I select an element within a table using Python Selenium? Python Selenium 在特定日期查找元素(标题) - Python Selenium find element (title) in a specific date 如何在python中使用select下面的元素selenium - How to select the following element using selenium in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM