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’]”)
Similar Posts:
- [Solved] antD table Componet Error: warning.js?2149:7 Warning: [antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.]
- Pytest @pytest.mark.parametrize Example
- Four ways to solve selenium’s error “element is not clickable at point…”
- [Solved] Selenium Error: ElementClickInterceptedException
- Message: stale element reference: element is not attached to the page document error solution
- How to Solve Web APP Tag Error in Web.xml
- Installation ‘lrzsz’ package and its error reporting solution
- Selenium: How to Solve Staleelementreferenceexception error (Three Methods)
- [Solved] Query DataTables Error: Cannot reinitialise DataTable
- selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document