selenium.common.exceptions.InvalidSelectorException: Message: An invalid or illegal selector was specified

selenium.common.exceptions.InvalidSelectorException: Message: An invalid or illegal selector was specified

I am trying to write a script to handle web pages that has multiple elements. This element once clicked will lead to a new window. But my script has problem in identifying the element. I need help to locate element and handle multiple windows

I am trying to write a script to handle web pages that has multiple elements. This element once clicked will lead to a new window. But my script has problem in identifying the element. I need help to locate element and handle multiple windows

I tried finding Xpath by using Chrome but it is not the same in Internet Explorer. I also tried using CSS selector it doesn't work. Says it is invalid.

Code for the function test_google_search_page: def test_google_search_page(self): driver=self.driver driver.get("http://xxxx.com") str1=driver.title print(str1)

    #get the window handles using window_handles
    window_before=driver.window_handles[0]
    print(window_before)

#driver.find_element_by_xpath("//*                   [@id='2ccb50dfc61122820032728dcea648fe']/div/div")
driver.find_element_by_css_selector("#\32  ccb50dfc61122820032728dcea648fe > div > div")
window_after=driver.window_handles[1]

driver.switch_to.window(window_after)
str2=driver.title
print(str2)
print(window_after)

self.assertNotEqual(str1,str2)
print('This window has a different title')
driver.switch_to.window(window_before)

self.assertEqual(str1,driver.title)
print('Returned to parent window. Title now match')

ERROR: test_google_search_page (main.GoogleOrgSearch)

Traceback (most recent call last): File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\Python programs\SNOW2.py", line 21, in test_google_search_page driver.find_element_by_css_selector("#\32 ccb50dfc61122820032728dcea648fe > div > div") File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 598, in find_element_by_css_selector return self.find_element(by=By.CSS_SELECTOR, value=css_selector) File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value'] File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidSelectorException: Message: An invalid or illegal selector was specified


python css selenium

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Python Selenium Introduction & Installation

This is our first article with video training on Python Selenium, in this article we are going to talk about Introduction & Installation of Selenium. we are

Python Selenium Web Elements Introduction

This is our second article on Python Selenium, in this article we are going to learn about Web Elements Introduction in Python Selenium. in the first

Python Selenium Web Driver Navigation Command

Python Selenium Web Driver Navigation Command - In this article we are going to learn about Selenium Web Driver Navigation Command in Python.so using Selenium

Selenium with Python

Selenium with Python

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.