2 回答

TA贡献1862条经验 获得超6个赞
为了使用元素中包含的文本来定位元素,唯一的选择是使用 XPath。
//a[./b[.='Edit']]
^ Start at the top of the document and find an A tag
^ ...that has a descendant B tag
^ ...that contains the text 'Edit'

TA贡献1871条经验 获得超8个赞
要定位<a>
具有降序<span>
文本作为编辑的元素,您需要引发WebDriverWait,并且visibility_of_element_located()
可以使用以下定位器策略之一:
使用XPATH:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(@id, 'thtmlb_button')][.//b[text()='Edit']]")))
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
添加回答
举报