更新时间:2023-08-26 12:29:34
查找所使用的元素:
sixth_item = driver.find_element_by_id("coption5")
To locate this element only by using coption you can use can use either of the following Locator Strategies:
使用XPATH
和starts-with()
:
sixth_item = driver.find_element_by_xpath("//*[starts-with(@id, 'coption')]")
使用XPATH
和contains()
:
sixth_item = driver.find_element_by_xpath("//*[contains(@id, 'coption')]")
使用CSS_SELECTOR
和^
(开头为通配符):
Using CSS_SELECTOR
and ^
(wildcard of starts-with):
sixth_item = driver.find_element_by_css_selector("[id^='coption']")
使用CSS_SELECTOR
和*
(包含通配符):
Using CSS_SELECTOR
and *
(wildcard of contains):
sixth_item = driver.find_element_by_css_selector("[id*='coption']")
您可以在以下位置找到有关动态CssSelectors的详细讨论:
You can find a detailed discussion on dynamic CssSelectors in: