How To Resolve SessionNotCreatedException In Selenium WebDriver

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is mukesh rotwani once again from learn hyphen innovation.com today in this video i'm going to talk about how you can handle session not created exception in seleni web driver i'm sure if you're working on selenium then you must have faced this exception and i will tell you the different fermentation in combination why you will be getting this exception and how you can fix it so it's going to be very interesting video and very easy solution so before i start i just want to show you the different kind of issues that you will be facing recently or you must have faced you know with previous version of selenium so this is very common exception which beginners will be getting or even advanced people will get which is session not created exception session not created the version of chrome driver only supports chrome 84 or whatever version this is one of the issue if i open another issue you will see again session not created exception but you can see a different reason now it says could not start a new session response code 500 and message is same the version of chrome driver is not supported it could be any other version third variation which is sometimes will not give you any hint what went wrong with your code so this says could not start a new session again it's part of selling not uh session or creator exception and this is sometimes little disturbing it says possible cause our invalid address of the remote server so if you're getting this kind of exception uh reason then you will get confused how to fix it so this quick video will guide you how you can fix it so first of all i just want to highlight that session not created is a child class of web driver exception so base class of this exception is web driver exception and if i show you all the web driver exception so web driver exception have all the sub classes okay so right now we are going to deal this session not created exception so the reason is simple session could not be created but we need to find out why this session has not been created okay so first of all let me show you my current chrome version so at the time of recording i am using chrome 89 and definitely now we need the driver right in order to start this browser so if you go to selenium.dev website which is official website of selenium just go to download section and if you come down you will see a section called browser section and if i just go to this chrome and if i click on this documentation so right now the latest stable release chrome 89 and this is in beta release so right now i'm using 89 so i have to use this the moment i download this okay so first of all i have already downloaded couple of versions okay so you can see i have downloaded already chrome 90 and chrome 84 and chrome 86 i will show you how you can get the previous version but let me also download this chrome 89 okay so i quickly downloaded chrome 89 so this is 84 86 90 and 89 so this is compatible with selenium right now so what i will do first of all i will show you the happy path that if you are starting new then what should be your approach so i will just create a random class name i already have created one package called chrome session i will just create this class name as chrome demo and i will be taking public static void main but if you're using test ng or junit you can take any of this unit as framework step number is we need to set this property right now i'm not using any web driver manager okay that is again a second approach that i will discuss but for the time being i will set a property called webdriver.chrome.driver and definitely i have to provide the path right so i will be using this path i will just copy its path and in double quotes i will simply pass here so in java either you can use one forward slash or two backward slash so here it's two backward slash so this is driver path we are giving now let me start a session web driver driver equal to new chrome driver and yes chrome driver and let me open any application doesn't matter because once your application is up and running rest everything will remain same so it's not dependent on which application you're automating so let me just quickly add google.com or maybe facebook.com www.facebook.com okay and yeah it should work now but i want to highlight couple of things first of all i am using maven project and i'm using selenium 4 beta1 the at the time of recording we also have beta2 so i will show you the different combination so i'm using beta1 as of now and chrome driver latest but let me try some previous versions so let's try this latest which is chrome driver 90 so i will change this to chrome driver 90. i have all the drivers in this folder which is chrome sessions i am giving path chrome 90. let's run this and let's see the exception it just it will try to start and you can see it started and closed immediately and you got this exception called selenium dot session not created exception fine but it says now could not start a new session possible cause are invalid address of remote server or browser startup failure so by looking at this message you will not have any idea right now let me show you any other version okay so chrome 90 is not working because my browser is 89 but i am using latest driver let me try 84 or maybe let me go in a reverse direction let me try with 86 and you will get the same exception let's see i will also show you how you can download the previous releases also like i have downloaded previous releases also right and exactly same exception so one solution use the one which is compatible so in my case if i double click on this you can see it's 89 my browser is 89 it should work so this time i have given the exact 89 my browser is 89 it should work and it started it will open facebook.com and it will quit perfect so first solution always use the compatible version okay if you're using 89 then sorry if your browser version is 89 you can go with 89 or 88 depends whether that driver is supported not now you will see a strange behavior the moment i change this to selenium 4 beta 1 to beta 2. now how can i get this the moment you go to mvnraposity.com and if you simply search selenium so click on the first one right now i was showing you with beta1 right now let me show you with beta2 so i just need to change this beta1 to beta2 okay let me save this and definitely if i give the compatible version it will work but this time again forcefully i will try to change it to let's say 84 or 86 or 90. let me just use 84. right click run as java application and let's see it started and it closed this time same driver same browser but i have changed the selenium version and this time you got the different trace this time it is giving me some meaningful message it says response code 500 session not created the version of chrome driver only supports chrome version till 84. now this makes sense to us and we can easily identify okay something is wrong with my driver version and i need to downgrade or upgrade depends on your browser version right now it doesn't matter you use 90 86 84 okay if that is not compatible you will get a clear cut message which you can easily fix it but if you go with beta 1 that was giving some horrible message which is little tough to understand now let me make one more change uh if i go back to okay you can try with these alpha releases as well i'm going to use selenium 3 stable version which is selenium 3.141.59 and again you will see a different exception trace so i will say 3.141.59 save this file and let's go back again my browser is 89 still i'm giving 84. run his job application and let's see what is the exception trace we will be getting and okay it gives some again some weird messages which is a little tough to understand but overall if you just try to read simply say session not created exception the version of chrome driver only supports till 84. okay let me switch back to driver 89 and as usual it should work so this is the first approach guys where i need to match which browser is compatible with driver and i have to download and use the same this is little tedious process second approach which i will show you which is very easy you don't need to remember the versions and everything you just web driver manager it will take care of everything but i hope you got the main reason so what i did i actually i tried different versions of selenium okay but the ray the main root cause was same the driver was not compatible but different version was giving me different exception trace so i hope in future if you get the same exception you will clear you will get this idea that yes something is wrong with the driver now the question comes how i have downloaded the previous releases right now let me show you how you can do that so as usual you can go back to selenium.dev downloads and come back come to this browser section again open this link which is chromium okay so you can see uh it is only giving me option to download the stable release and the beta release which is upcoming one click on any of the release and on the path you can see it is only giving me this path so just remove this give the path till index.html and you can see all the previous releases of chrome driver that we're using right so all the previous releases is here what i did before this video i downloaded 87 84 and 86 i guess and we also have the two latest one so in case if you want to download the previous one you can just head over to this url and you can download i just downloaded and i just renamed them so that i can have the clear picture that which driver is which version only for your understanding but generally we maintain only one driver right this is first approach which is completely manual second approach is using web driver manager now web driver manager i have a dedicated video on this that how this web driver manager works how it can download the drivers and everything so in this maven project i already have web driver manager as you can see i have one dependency and the version is 4.3.1 so whenever i will use this webdriver manager i just need to use one statement and that one statement will take care of which driver i have to use depends on which platform i'm using suppose i am using linux so it will download the linux binary if i'm using mac it will download the mac live or i will say driver for the mac and if i'm using windows definitely driver for windows which will be exe how do i use it i will simply say web driver manager dot if i'm using chrome i will go with chrome driver if i'm using edged i will go with s driver and firefox and so on in this example i am showing you with chrome driver and if i use the setup method now you don't have to worry about which driver which version everything is taken care by this particular statement so just right click run as java application and let's see just notice this console output so it's starting now it automatically used 89 so basically what it does first of all it will check in my cache if i have this 89 in my system or not if yes it will take from the cache if it is not available it will download and then use the same okay so that's all for this video i hope this was helpful so let me give a quick recap we tried creating the same scenarios with three different versions 3.141.59 beta1 and beta2 we were getting different exception tricks but the root cause was same browser was not compatible with the driver we tried different combination but the main goal is use the one which is compatible second approach which we have seen that we have to use web driver manager we just need to add the dependency in our home.xml file and in your program we just need to use webdrivermanager.chromedriver or dot firefox or h driver dot setup that's all for this video guys so in future if you get the same exception try this and if you still get the same exception let me know in the comment section and i will try my best to help you out in case if you're new to this channel then make sure you subscribe this channel share with your friends and i will see in the next video have a nice day bye
Info
Channel: Mukesh otwani
Views: 34,875
Rating: undefined out of 5
Keywords: How To Resolve SessionNotCreatedException In Selenium WebDriver, sessionnotcreatedexception selenium webdriver chrome, selenium webdriver, exception in selenium webdriver
Id: Riqa_goTMm4
Channel Id: undefined
Length: 14min 41sec (881 seconds)
Published: Wed Mar 31 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.