[英]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.