InvalidSelectorError: Compound class names not permitted error process

InvalidSelectorError: Compound class names not permitted error process

Environment: python3.6 + selenium 3.11 + chromedriver.exe

When we parse pages, always will encounter a lot of tag, how to pinpoint these tag, there are also many ways.

Today, while acquiring a node object with find_element_by_class_name, reported a mistake Compound class names not permitted.

Original code:

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

The revised Code:

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

or:

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

This two pieces of code are required to obtain a normal object.

 

to sum up:

When acquiring tag object contains multiple class names

Recommended:

find_element_by_css_selector(".xx.xxx.xxxxx")

or

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

 

Guess you like

Origin www.cnblogs.com/111testing/p/10990513.html