场景:
python+selenium+chrome,class name定位元素时,class属性值带有空格会报错:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".fm has-soutu"}
解决方法:
用小数点:. 代替空格
如:fm has-soutu => fm.has-soutu
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
print(driver.find_element_by_class_name("fm.has-soutu"))
driver.quit()