InvalidSelectorError: Compound class names not permitted报错处理
Environment: python3.6 + selenium 3.11 + chromedriver.exe
When we parse web pages, we always encounter a large number of tags, how to pinpoint these tags, there are also many ways.
Today, when I used find_element_by_class_name to get a node object, an error was reported 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’)
Modified 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”)
Both pieces of code work fine to get the desired object.
To summarize.
When getting a tag object that contains multiple class names
it is recommended to use.
find_element_by_css_selector(“.xx.xxx.xxxxx”)
or
find_element_by_css_selector(“[class=’xx xxx xxxxx’]”)