Fixing SessionNotCreatedException - Selenium Exception Type

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all welcome to this session in this session i am going to explain and practically demonstrate how to fix one of the selenium exception types that occur during automation that is session not created exception so let's get started first of all when do we get this kind of exception during selenium automation if you are using any browser driver executable file which is incompatible with either selenium version or browser version in that cases we'll get this session not created exception let me explain again in a detailed manner let's say for running your selenium automation scripts you are using some browser driver executable file say for chrome browser we have chromedriver.exe for firefox browser we have geckodriver.exe such kind of browser driver executable files they have some versions right this browser driver executable files have some versions if this browser driver executable file having some version is incompatible with either selenium version or it is incompatible with some browser version itself then in that case we'll get this kind of exception known as session not created exception now let me practically demonstrate one of the ways where we get the session not created exception let's say i am using an incompatible browser driver executable which is incompatible with this browser version that i will show you now practically guys okay here we have the sample selenium project which is already created and configured with selenium guys okay this is a sample java project which is already configured with selenium as you can see the latest version of selenium as per today's state have used okay so and we have the sample class which is having the main method and here i am going to write the automation code let me write the automation code webdriver driver i am going to use a chrome browser so new chrome driver okay like this and uh import this web driver you see over the mouse import this again over the mouse import this chrome driver class from selenium done now say driver dot manage dot window dot maximize i'll go to one sample application page let's say i will use some internet heroku or whatever it is internet heroku some sample application i'm going to use copy this url and paste it here and uh i simply want to print the title of this page okay driver dot get title driver dot get title that's it and after that i want to read the browser driver dot very simple automation script have written but for this particular script to run how to provide the path of the chromedriver.exe file that is a browser driver executable file i have to queue right so so how to give that so here i will get say system dot okay set property just take this one system.set property here i have to say webdriver dot chrome dot driver okay and here i need to give the path of that chromedriver.exe file but that chromedriver.exe file should be compatible with my browser version so what is the chrome browser version i'm using let me show you here i'll go to this i'll open this chrome browser and just click on this three dots say help and say about google chrome now you will get the browser version of this chrome so it's kind of up to date and that's giving me the chrome browser version in my machine is point seven 97.0.4692.71 okay so i need to download a proper chrome browser's driver executable file for selenium okay from where selenium dot dev i'll go to the official website of selenium selenium dot dev click on the downloads i'll scroll down to the browser section here and here we have to see the chrome and i need to click on this documentation let me click on this documentation now once i click on the documentation i'm taken here and here i see something known as downloads all version available here in downloads click on that you'll be taken to this page so if i have to take a compatible chrome driver executable file okay for my chrome browser version okay it should be same right the chrome browser version should match with the chromedriver.exe file so it is like uh 0.71 this one right 97.04692 and dot 7 one this one is compatible okay let me download the compatible one first let me download this so here windows 32 version is there only in windows on my machine is windows so i'll be downloading windows since 64 is not there i'm downloading the 30 bit so let it download guys let it download let's wait for this chrome driver zip file to get downloaded first yeah it got downloaded let me go to the place where it got downloaded this is the place let me expect this uh let me extract this zip folder now i'll get that chromedriver.exe file now okay so let it extract guys let it extract once extracted we'll get that chromedriver.exe file see i got this chromedriver.exe if i'll copy this and here i'll create a folder at the same downloads location only i'm creating a folder guys just to remember that this is a compatible compatible chrome driver version which was around 97 and so on right that 97 thing okay i'm just giving some 97 here and uh just go into this folder and paste it fine now come back and delete this zip file and delete this normal folder okay only this one having the compatible chromedriver.exe file is available similarly let me download one more chrome driver executable file of an incompatible version with my browser okay so here i have the browser version as this 97.0.469.71 but from here i will download some other version let's say i will go with the 95 okay chrome driver 95 i'll go which is mismatching right with my browser version let me click on this will take me to this page and from here i'll download again the chrome driver the file but this is incompatible 95 point something is there but i want is my browser version is 97.70 it got downloaded guys let me show in folder extract this again extract i'll get the zip file i'll get this chromedriver.exe after the zip file gets extracted this is a chrome driver now i'll create one more folder here guys saying incompatible incompatible chrome driver version hyphen 95 okay my browser version is 97 point something but i am downloading the chrome driver exe file having 95 version which is incompatible unnecessary files zip files and all those stuff i'll delete guys okay so i only have these two folders now one is uh incompatible another one is compatible okay so let me go to my eclipse id here i need to give the path of that chromedriver.exe first i will give first i will give this a compatible path okay i'll give a proper one okay compatible one so right click on this right click on this guys and say show more options and say properties mine is windows 11 so i have to say show more options otherwise it will not come so if you are using windows 10 you will get the properties directly when you right click copy copy this path guys okay this is the location right this is the location so copy entire location ctrl c and come here and paste this paste the location now say double backward slash followed by chrome driver in that folder location we have this chromedriver.exe file okay i gave that that's it so this one is a compatible one okay compatible chrome driver version i gave you see compatible chrome driver version i gave now if i run the script it will work seamlessly without any problems you will not get any exception you will not get any session not created exception here so it will work seamlessly okay it will open the chrome browser maximize the browser it will open this application url in the browser it will get this title of the page and print in the output and then we'll close the browser everything will happen seamlessly you see without any exception coming because this chrome driver version that i'm using is compatible with my chrome browser version you see everything happened without any exception you see there is no exception here in the output what if i update this path okay so here instead of giving the path of that thing i'll remove this path again and go to that place where i have downloaded and kept my incompatible version of the chrome driver also i'll go here and right click on this chrome driver and say show more options and properties and copy this path where this incompatible version of the chromedriver.exe file is available and come back here and paste it and at the end i will add double backward slash chrome driver.exe that's it now this this time we have given the incompatible driver version which is incompatible with my browser version now if i run this code this time you should get that exception that is nothing but session not created exception let's run this and see you see you already got the exception right the script has not run and instead of that you got the exception that i am talking about that is session not created exception could not start a new session response code 500 session not created the version of the chrome driver that you have used is incompatible with the chrome browser version okay so your chrome version 95 you have used that is incompatible so that's what okay that's what the message is there this whatever the chrome driver version chromedriver.exe file version you have used right that only supports the chrome browser version of 95 but your chrome browser version is 97 that's why it's not supporting and hence you got the exception it is saying so how to fix this exception one way of fixing this exception is to give a proper chromedriver.exe file of a compatible version that is one thing or okay if you don't want to take this headache there's one more way guys that is you can take the help of the web driver manager okay what is this webdriver manager so what we have to do here is just go to this mvn repository let's say here i will go to the mvnrepository.com and here search for web driver manager okay this will also solve the problem guys either you have to give the correct version chrome driver exe compatible version you have to give or you have to go to this uh ambient repository and uh search for this web driver manager and click on this web driver manager take the latest version as per date and copy this maven dependency tags and go to your eclipse id open the pom.xml file and here configure this project apart from configuring the project with selenium java library dependencies you also need to configure this project with web driver manager this is something extra okay web driver manager is extra now save this okay once copied this dependencies save this the jar files for the web driver manager will be automatically downloaded and they will be configured in this project scroll just close this now instead of writing the system.set property where you have to manually give the correct chrome driver version or whatever it is driver version you have to give right instead of doing that simply type web driver manager dot chrome driver okay sorry there is a mistake here let me remove that save this once so let me write it again web driver manager dot chrome driver chrome driver dot setup okay like this you have to write this you don't have to do anything guys okay webdriver manager will take care of the compatible chrome driver or browser driver executable which is required for your browser versions to run okay so in your browser for example in your chrome browser what is the version you have 97.0.4692.71 okay so when you use this statement guys webdriver manager will detect in your machine the chrome browser is having which version it will find it out and accordingly it will automatically download the chrome driver compatible driver is google file for you that's what it will do guys you don't have to take any go to the website manually and uh download it okay so this is automatic way and the best way i can say okay rather than you giving the chrome driver exe file and check after checking the compatibility and sometimes it goes wrong and will result in session not created exception instead of going to that case if you use this kind of web driver manager right then it will take care of the things automatically it will take care of the incompatible things and we'll take and find out which one is compatible and all automatically guys you don't have to do anything simply run this code you will see in the output guys in the eclipse output console you will see what the web driver manager is doing so you will see some number coming here for chrome driver which chrome driver the web driver manager has picked up for our chrome browser that is there in my machine let's see in a while you see you see it has picked up chrome driver version 97.0.469.71 automatically i didn't say that web driver manager knows that in my machine the chrome browser version is this one so it automatically downloaded this chrome driver version also which is compatible with my chrome browser version okay same version it has picked up so that's what is the advantage this is the simplest way of fixing this exception guys either you have to give the proper driver executable file version or just go with the webdriver manager these are the two ways in which you can solve this problem so hope guys you understood how to fix one of the selenium exception types that occur during automation that is session not created exception so that's it guys thank you bye
Info
Channel: QAFox
Views: 4,028
Rating: undefined out of 5
Keywords: SessionNotCreatedException, Selenium Exception Types, Selenium WebDriver, Fixing Exception, Incompatible Driver Version, When does it occur, Selenium Automation, Selenium Testing, Testing Tools, Software Testers, Test Automation, Automation Testers, Automation Testing, Automation Engineer, Automated Testing, Automated Software Testing, Testing, Free, Full Course, From Scratch, Tutorials, Playlist, Video Course, Beginners, Made Easy, Easy
Id: OYjE-PYP3lM
Channel Id: undefined
Length: 15min 9sec (909 seconds)
Published: Fri Jan 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.