Zak Dyer

Zak Dyer

1548294942

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 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

What is GEEK

Buddha Community

Your #\32 ccb50dfc61122820032728dcea648fe > div > div CSS selector is indeed invalid. Please refer to the CSS selector grammar specification.

Did you mean: #2ccb50dfc61122820032728dcea648fe > div > div? Even though, it’s impossible to give you a specific correct selector without seeing the HTML source of the page and element you are trying to locate.

The 2ccb50dfc61122820032728dcea648fe id itself though looks auto-generated, you should probably look for alternative locators to get to the desired element, this topic might help to get an idea of how to approach locating elements with selenium:

Zak Dyer

Zak Dyer

1548294942

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 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

Ilene  Jerde

Ilene Jerde

1596801420

Selenium Tool Suite - Components and Features

Selenium is an automation testing tool; it is primarily used to test websites and web applications; it is an open-source tool. With the help of Selenium, test cases can run directly in web browsers, just like a person operating the web browsers. It supports many web browsers such as Opera, Safari, Chrome, Firefox, IE, etc. There are several different sub tools to support different automation test approaches. In this article, we will learn about selenium tool suite, its components and features. So let’s start!!!

#selenium tutorials #selenium grid #selenium ide #selenium rc #selenium tool suite #selenium webdriver

Anthony  Dach

Anthony Dach

1627025027

What's New in Selenium 4?

The newly released Selenium 4 is creating a lot of buzz and the complete testing community is looking forward to exploring its updated features.

Selenium has gone through a tremendous evolution since its introduction and that’s the reason today it is the most popular and powerful automation testing tool. The newly released Selenium 4 is creating a lot of buzz and the complete testing community is looking forward to exploring its updated features.

Before we dive into Selenium 4, let’s have a brief introduction to its previous versions. Selenium 1 was declared as the free open source automation testing framework in the year 2004 consisting of selenium IDE, RC, and web driver. Whereas, the Selenium 2 released in 2011 consisted of the IDE, Web driver, and Grid. The RC server was merged with the web driver, as the web driver facilitated easy automation scripting for the browsers. Selenium 3 was officially released in 2016. One of the most noticeable changes in selenium 3 was the replacement of the selenium core with the web driver-backed option, the introduction of the gecko driver, and W3C web driver integration.

With the aim of executing much seamless, accurate and faster test automation, Selenium 4 was released on 24th April 2019. So let’s unleash all the major features of selenium 4 which sets it apart from the earlier versions delivering better test automation. There are a lot of exciting features in Selenium 4 across the complete suite i.e. Selenium IDE, Webdriver and Grid. In Selenium 4 though the Webdriver captures the spotlight, we will cover the updated features of selenium IDE and selenium grid. So first of all let’s define the different user groups for the Selenium suite.

Selenium is a suite of tools that caters to the various requirements of the project such as:

  • Selenium IDE (Integrated Development Environment) Supports Rapid test development. This record/run tool helps in preparing test cases. Selenium IDE is an easy-to-use tool from the Selenium Test Suite which is used for developing automated test cases for web applications.
  • Selenium Webdriver provides flexible and seamless automation through a friendly and flexible API. It can perform automation in almost all programming languages.
  • The grid helps in providing automation testing by distributing and running the test cases in multiple machines simultaneously.

Let us explore the features of Selenium 4 across the different Selenium Tools.

#selenium #automation testing #selenium automation #selenium automated testing #selenium test automation #selenium 4

Anthony  Dach

Anthony Dach

1620462169

How To Get Attribute Value In Selenium WebDriver

While you are automating your test cases with Selenium automation, here is how to start implementing Selenium getAttribute() method to get the best results.

Introduction

Testing a web page can be a gargantuan task, considering all the elements and variables that come together to make a page work. Selenium automation is a great way to overcome these challenges and automate everything you would manually do. For example, Selenium makes it so much easier to take a screenshot using Python instead of doing it manually every time you come across a website issue.

Similarly, there are multiple scenarios while writing automation test cases when we need to verify a specific attribute on the web page. To ease our execution, the method to getAttribute() in Selenium comes to the rescue. In this blog, we will understand what an attribute is and how we can handle web elements’ attributes using the Selenium getAttribute() method.

Let’s get to it, shall we?

#selenium #webdriver #selenium automation testing #selenium automation #selenium - web browser automation #selenium automated testing #get attribute

Anthony  Dach

Anthony Dach

1623834757

How to Upload and Download a File Using Selenium

Selenium is one of the most—if not the most—popular names for browser automation tools. And even though you can use…

Selenium is one of the most—if not the most—popular names for browser automation tools. And even though you can use its automation power for any purpose you like, most people use this tool to test web applications.

We’ve published many posts about Selenium. Today, we add another one to the list by teaching how to upload and download files to websites using the tool.

We’ll start with a brief definition of Selenium, covering the three main versions in which you can find it. Then, we get to the main part of the post, where we’ll cover how you can upload and download files using Selenium, in that order.

Before wrapping up, we share some final considerations, including an alternative to using Selenium for this kind of task.

#uncategorized #selenium #introduction #selenium #selenium grid #testim #selenium ide