InvalidSelectorError: Compound class names not permitted報錯處理

InvalidSelectorError: Compound class names not permitted報錯處理css

環境:python3.6 + selenium 3.11 +  chromedriver.exepython

咱們在解析網頁的時候,老是會遇到大量的tag,如何精肯定位到這些tag,也是有不少的方法。chrome

今天在用 find_element_by_class_name獲取一個節點對象時,報了個錯 Compound class names not permitted.
spa

原始代碼:orm

selected_div = driver.find_element_by_class_name('next-pagination next-pagination-normal next-pagination-medium medium pagination')對象

修改後的代碼:blog

 selected_div = driver.find_element_by_css_selector("[class='next-pagination next-pagination-normal next-pagination-medium medium pagination']")element

或者:selenium

 selected_div = driver.find_element_by_css_selector(".next-pagination.next-pagination-normal.next-pagination-medium.medium.pagination")string

這兩段代碼均可以正常獲取到所需對象。

 

總結:

在獲取包含多個class名稱的tag對象時

建議使用:

find_element_by_css_selector(".xx.xxx.xxxxx")

或者

find_element_by_css_selector("[class='xx xxx xxxxx']")

相關文章
相關標籤/搜索