定位元素 (字符串)和方法 做分离
# 导包 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 定义driver driver=webdriver.Chrome() # 打开浏览器 driver.get("https://www.baidu.com") # 获取元素 # 分离出地位的元素 loc="#s-hotsearch-wrapper [class='title-content-title']" # <class 'str'> print(type(loc)) elements=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,loc))) print(elements) for e in elements: print(e.text) # 退出 driver.quit()