Python 3.x python中的selenium需要CSS模式来定位元素
这是HTML语法,但我想使用find_element_by_css_选择器使用值“ADD QUERY”来定位元素 HTML的图像:Python 3.x python中的selenium需要CSS模式来定位元素,python-3.x,selenium-webdriver,xpath,css-selectors,webdriverwait,Python 3.x,Selenium Webdriver,Xpath,Css Selectors,Webdriverwait,这是HTML语法,但我想使用find_element_by_css_选择器使用值“ADD QUERY”来定位元素 HTML的图像: 要定位元素,可以使用以下任一方法: 使用CSS\u选择器: element = driver.find_element(By.CSS_SELECTOR, "div.global-button-primary.telemetry-button") element = WebDriverWait(driver, 20).until(EC.visi
要定位元素,可以使用以下任一方法:
- 使用
:CSS\u选择器
element = driver.find_element(By.CSS_SELECTOR, "div.global-button-primary.telemetry-button")
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.global-button-primary.telemetry-button")))
- 使用
:XPATH
element = driver.find_element(By.XPATH, "//div[contains(@class, 'global-button-primary') and contains(@class, 'telemetry-button')][contains(., 'ADD QUERY')]")
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class, 'global-button-primary') and contains(@class, 'telemetry-button')][contains(., 'ADD QUERY')]")))
- 使用
:CSS\u选择器
element = driver.find_element(By.CSS_SELECTOR, "div.global-button-primary.telemetry-button")
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.global-button-primary.telemetry-button")))
- 使用
:XPATH
element = driver.find_element(By.XPATH, "//div[contains(@class, 'global-button-primary') and contains(@class, 'telemetry-button')][contains(., 'ADD QUERY')]")
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class, 'global-button-primary') and contains(@class, 'telemetry-button')][contains(., 'ADD QUERY')]")))
- 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC