Selenium Webdriver Installation

It's good to have someone to talk to all time, so I created a voice assistant. 

Check the previous post for installing pyaudio module where the voice assistant will listen to my voice!!

Let's start with other features of a voice assistant. In this post, I will capture the following topics:

Installing selenium web driver using pip 

Now, If I request anything from 'Google Search' to July, it has to access the browser and get the information. So, now we are going to install selenium using pip. 

Selenium Module/Tool

Selenium is an open-source web-based automation tool. Python language is used with Selenium for testing. It has far less verbose and easy to use than any other programming language. The Python APIs empower you to connect with the browser through Selenium.


Once installed, first check if it is installed.


Installation of Chromedriver

Now, this selenium is just a tool to interact with browsers to test web applications. Selenium Webdriver opens URL on a browser and interacts with webpage like buttons, links, text boxes, etc., But, Selenium can't do all these tasks on its own. It needs some help from the browser side as well to perform all these tasks. So, we do use Chrome driver to perform these actions on Chrome browser. ChromeDriver is a standalone server to implement WebDriver's wire protocol for Chrome. 

As a C programmer, I'm not aware of how we can open the browser automatically using script and type URL. Now, this feels so interesting. 

I installed the latest/current release of the chromedriver for windows 32 from this URL https://sites.google.com/a/chromium.org/chromedriver/downloads



The below is my program and which threw error 'SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape'


The below screenshot was the error I got. 



Later, I added 'r' before the chromedriver path and got rid of the above mentioned error. or we can change \ to / to resolve this error. 


Working out on these kinks are bit irritating. Then I got the below two errors:

1. ERROR:device_event_log_impl.cc(214)] [15:58:57.331] USB: usb_device_handle_win.cc:1054 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F). 

2. selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 91



To solve this version error, either I need to downgrade the ChromeDriver version or upgrade the Chrome version. As my browser version is up to date, I downgraded the chromedriver version. 








As of now we are able to open the wikipedia page, so now let's try to search on the wikipedia box.



Next, we need to click on the search bar to enter the query which needs to be searched. 

There are two things: 

1. find.element.byxpath


2. Clicking the search bar

Few times, the below error occurred. 

PS E:\Mini_project\Speech_asst> & C:/Python/python.exe                                                          e:/Mini_project/Speech_asst/selenium_web.py                                                                          

DevTools listening on ws://127.0.0.1:56486/devtools/browser/0320445a-c8c7-4413-b322-       f37a9b45fd9c                                                                                                                                
Traceback (most recent call last):                                                                                                 
  File "e:\Mini_project\Speech_asst\selenium_web.py", line 32, in <module>
    wdr = infow()
  File "e:\Mini_project\Speech_asst\selenium_web.py", line 7, in __init__
    self.driver = webdriver.Chrome(executable_path=r'C:\Users\hai\chromedriver_win32\chromedriver.exe')
  File "C:\Python\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 90
Current browser version is 92.0.4515.131 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe

PS E:\Mini_project\Speech_asst>

pip install webdriver-manager                          


After this installation, I added the below two lines additionally.  
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
Commented the below line
#self.driver=webdriver.Chrome(executable_path=r'C:\Users\..\chromedriver_win32\chromedriver.exe')


<to be updated>


https://stackoverflow.com/questions/49788257/what-is-default-location-of-chromedriver-and-for-installing-chrome-on-windows

https://stackoverflow.com/questions/60296873/sessionnotcreatedexception-message-session-not-created-this-version-of-chrome/62127806

https://stackoverflow.com/questions/63134279/how-add-wake-up-function-in-python

https://github.com/ggeop/Python-ai-assistant

Comments