Selenium Java Coding Tips & Tricks #13 |Selenium WebDriver Common Exceptions — Transcript
Full transcript
- 0:00yeah all right so today we are going to see uh one of the most important concept common
- 0:09linear web driver exceptions so we will get common exceptions most of the time web driver
- 0:14exceptions when you're writing automation test scripts or when you're running your
- 0:18automation test scripts we will commonly get some kind of exceptions so what is the main
- 0:23objective of exception so why we'll get an exception why we'll get an exception normally
- 0:31because of some input is not valid then uh we'll get some exception so what is the purpose of uh
- 0:37concept of exception handling what's the main concept of exception handling suppose if there
- 0:42is any exception so we should not make our code or script terminate immediately so instead of that we
- 0:48need to prop we need to provide a proper message uh then we will exit from the code so we should
- 0:55not immediately terminate the code with proper message we need to exit from the code whenever you
- 1:01get some exception so that is the main objective of using exception handling right even selenium
- 1:07also there are different type of exceptions are there so we will discuss one by one around 15 to
- 1:1220 exceptions are there which are very commonly uh we will see while executing our test or framework
- 1:19and first we'll see what is that exception name and when you will get that type of exception
- 1:24and how we can handle that exception the first one knows a such element exception so very very
- 1:30common exceptions many times we have seen this exception no such element exception so what is no
- 1:36such element exception when you will get it occurs when an element with the special specified locator
- 1:42cannot be found in the Dom so for example what let's say I provided one locator let's say by.
- 1:48ID some ID or some name or some xath I provided but with that uh with this particular attribute
- 1:55or with this xath or with this CS there is no element available in the web page in that case
- 2:01you will get a no such element exception so trying to interact with the element that doesn't exist on
- 2:06the web page itself so whatever the locator you passed here corresponding element itself is not
- 2:12available in the web page so in that particular case you will see no such element exception okay
- 2:19so suppose when you write statement like this suppose here the ID is not available or xath or
- 2:25CS is not available the xath ID name you have used is correctly written but but the corresponding
- 2:30element is not available the element itself is not available so in that case you will get a no
- 2:36such element exception so how we can handle this so normally you can put in the TR catch block so
- 2:43you can put that element in the tri catch block and in the catch block you can say no such element
- 2:47exception and simply provide a message to the user like element not found along with the proper
- 2:53message okay and uh sometimes maybe the element takes some time to load on the web page page so
- 3:00you can also wait for the element for some time let's say you can use web driver weit like this
- 3:05and wait until expected conditions do presence of element located and then pass the locator
- 3:11and it will wait for the element and once it is present on the web page then it will return the
- 3:16web element and then it will continue the process but even after 10 seconds if the element is not
- 3:22available me then again you'll get the timeout exception then because we use web driver weight
- 3:28also right even web driver weight is also exceeded the time so then you will get the time out
- 3:32exception okay sometimes we can handle through web driver weight even web driver weight is also not
- 3:38able to solve means there is some problem with the element so that element is not available so this
- 3:44is how we can handle it we can put the TR catch block the element locator along with this we can
- 3:49put Tri block and catch block we can just simply provide the message to the user so that is no such
- 3:55element exception so when you will get this if the locator is correct but corresponding element is
- 4:01not available or not present on the web page then you will get no such element exception you need to
- 4:08remember guys because in interview definitely they will ask some kind of exceptions at least four
- 4:13to five exceptions you need to remember very very important and whatever exceptions I have noted in
- 4:19this document all are important 15 to 20 types of exceptions very frequently we'll get these
- 4:25exceptions you should remember them now the next exception is element not visible exception this
- 4:31is another type of exception element not visible exception so when this will occur it occurs when
- 4:38element is present in the Dom but it is not visible on theb page okay you understood my
- 4:45point element is present in the Dom but it is not visible and what kind of element it is it is there
- 4:54in the DM but it is not visible on the page this is basically hidden element right hidden element
- 5:00so occurs when element is present in the DM but it's not visible on the web page then you
- 5:05will get a element not visible exception so normally we will capture the element and then
- 5:11we will try to perform the action click action then you will get this exception identifying the
- 5:16element is working fine but when you perform the action it is not visible so you'll get element
- 5:23not visible exception right so how we can handle this normally so whenever you get an element first
- 5:30verify the status okay if it is displayed then click on the element okay if it is not displayed
- 5:37obviously it will throw exception so we need to handle that in the catch block element not visible
- 5:41exception and provide the proper message to the user element is not visible sometimes even though
- 5:48it is not visible on the web page we can make it visible forcefully and then we can perform the
- 5:53action using JavaScript executor it is possible so how we can make it visible Js JavaScript execut
- 6:00execute script arguments of zero style. display. block element whatever element we are looking for
- 6:06can pass the element and this par statement will make our element visible on the page after it is
- 6:13visible then we can perform the click action so most of the times this solution will solve it
- 6:19especially when you have hidden elements so the elements are present in the DM but they
- 6:23are not visible on the web page so we can make those elements visible using JavaScript executor
- 6:30and then we can perform the click action so this will solve the problem and we can also
- 6:35handle this using TR catch block suppose if you don't if you're not using JavaScript executor so
- 6:39definitely that will throw exception so you can handle the exception using TR catch block but if
- 6:44you're using JavaScript executor it will able to handle it then you don't need to use TR C
- 6:48block so this is element not visible exception now third one stale element reference exception stale
- 6:59element reference exceptions very very important and very popular exception stale element reference
- 7:06exception so when you will get this the exception is thrown when an element is no longer attached to
- 7:12the DM usually after a page update or refresh very very important exception guys suppose you captured
- 7:22some element and you have performed some action immediately it is working fine but after writing
- 7:28some piece of code suppose you have written some piece of code for loading page or refreshing the
- 7:32page after that again if you're trying to perform or after that you're trying to locate this element
- 7:38then you'll get a stale element refer exception so stale is nothing but what whenever you refresh
- 7:44the page or whenever you update your page the element becomes stale so the locator may not
- 7:50work so you need to again locate the element one more time so how we can handle this we need
- 7:55to just relocate the element one more time we need to write a locator for example let's say
- 8:00here I have located my element and when performing the action it is throwing stale element reference
- 8:05exception so immediately in the catch block what you need to do again relocate the same element
- 8:10write the whole thing again one more time and then perform the action so this will solve the
- 8:15problem stale element reference exception can be solved by relocating the element once again
- 8:21because whenever you refresh the page or whenever you update the page or reload the page the same
- 8:26locator may not work one more time time so you need to again keep on uh Rite the same locator
- 8:33one more time that is stale element reference exception steel element reference exception
- 8:42so let me give you an example so when it will happen normally most of the times you will see
- 8:48this exception let's say uh this is my automation script let's say in the first place here I have
- 8:53located my element this is my element okay and my element is here now I have done some activity here
- 9:01and here my I refreshed my page and again this element I'm trying to use it here so then what
- 9:08happens we will get a stale element reference exception because you have done some update or
- 9:14you have done some refresh after locating this element so here what you need to do again you
- 9:19need to write a locator here one more time you need to locate the element and then you will
- 9:23get the you can continue the action so that you can do using TR catch block so this say
- 9:29stale element reference exceptions whenever you refresh the page or whenever you update the page
- 9:35the element becomes stale so in that case you will get a stale element exception what is the
- 9:40solution for this you just relocate the element in the catch block next one invalid element State
- 9:47exception invalid element State exception so when it will thrown when attempting to interact with a
- 9:57element that cannot be interact Ed with such as disabled form field entering text into disabled
- 10:04text field very important most of the times it will happen suppose invalid element State
- 10:12exception invalid element State exception let's say you have some input box and currently it is a
- 10:19disabled State you you can't enter any value but still you are entering the value by using send
- 10:24Keys method so because it is a disable it cannot it is not allowed to to provide any value into
- 10:30it so in that case you will get invalid element State exception currently the state of element is
- 10:36not ready to accept the data or accept the value so in that case we'll get a invalid element State
- 10:44exception if it is enabl then only we can pass or we can interact with the element not only
- 10:49input box in case of buttons also sometimes it will happen suppose button is a disabled but you
- 10:54trying to click on that button in that case also you'll get invalid element State except
- 11:00so first of all before performing any action on the element that element should allow us
- 11:03to perform the action it can be click or can send Keys whatever so otherwise it will throw invalid
- 11:10element State exception so for example here I have taken some input field and I'm passing
- 11:15the send Keys method if it is a disable then the send Keys method will throw invalid stale
- 11:20element exception so again how we can handle this sample we can put the tri catch block so we can
- 11:26just put the input field in the tri block and pass this value if it is through an exception
- 11:31catch block you can handle this invalid element State exception and just provide the message to
- 11:36the user like cannot interact with the element because it is disabled something like that it
- 11:41can provide some user defined message to the user okay so this is invalid element State exception
- 11:48if the element is disabled if you are trying to perform some action on that element then you will
- 11:53get an invalid element State exception this is one more important thing now next one element click
- 12:02intercepted exception this is also very common exception most of the times we have seen this
- 12:07element click intercepted exception element click intercepted exceptions occur when another element
- 12:15abstract The Click action another element abstract The Click action element click this exception is
- 12:22specifically for clicking when you're clicking on checkbox or when you're clicking on the radio
- 12:27button or when you're clicking on the button or L you will get element click intercepted exception
- 12:32so when you will get these exceptions suppose uh you have some web page and you are trying to click
- 12:40on this link or button and you have S you have written code properly and it is trying to click on
- 12:46this but when you're launching the page sometimes the page is not maximized sometimes page is small
- 12:53size page is open okay and sometimes elements is overlapped in that case what happens the another
- 13:00element will abstract The Click action so it is not allowing to click on the particular element
- 13:06maybe the because of overlapping because of the size of the page it is not allowing us to click on
- 13:11that element so in that case you will get element click intercepted exception it is basically
- 13:17interrupted The Click action so element click intercepted exception you will get whenever the
- 13:24another element abstract The Click action so for example I have located a button element I'm just
- 13:30performing The Click so if any other element is overlapped or any other element is disturbing the
- 13:35process or thing then you'll get this exception it's not allowing to perform the click action
- 13:40then how we can handle this you can put in the try catch block so try button in the try you can
- 13:45capture the button perform the click if it is not able to click element clicker interception will be
- 13:49return and then you can provide proper message to the user but how we can handle this suppose this
- 13:56is not problem of user actually so we can still handle how we can handle using explicit weight
- 14:02or JavaScript executor we can use so most of the times we can solve this element cck intercepted
- 14:07exception either by using explicit weight or by writing JavaScript executor there are two methods
- 14:12are there to solve this problem first method using explicit weight so you can just create a
- 14:19a web driver weight explicit weight and wait until element to be clickable this is the conditional
- 14:25method we have to use so once the element is able to click if the condition matches then we can
- 14:31perform the click action so mostly this will solve the problem element click intercepted exception
- 14:38okay so in case even explicit weight is also not able to solve then you can use JavaScript executor
- 14:44approach so JavaScript executor definitely will solve the problem because we are internally
- 14:49directly executing the JavaScript instead of inter instead of running the web driver command
- 14:55so js. execute script arguments of zero means what what whatever element we are passing here that is
- 15:01stored in arguments of zero then we are performing The Click action through JavaScript executor so
- 15:06element so element click intercepted exception we can solve either by using explicit weight
- 15:15or by using JavaScript executor okay and if you still want to handle this then you can again put
- 15:22in the tri catch block okay so uh in the cat block directly you can put the solution okay so if it is
- 15:31throw exception then alternative you can try with explicit weight alternate you can put Javascript
- 15:35executor that you can put in the catch block that will automatically solve the problem so element
- 15:40click intercepted exception when you will get this exception if any element any other element
- 15:46interrupt the process or interrupt The Click action or interrupt any other action you will get
- 15:51a element click Interceptor exception most common exception next element not intractable exception
- 16:02sometimes you'll get this inter element not intractable when this will occur when the element
- 16:08present in the DM the element is present in the DM but it is not in the state to be interacted it
- 16:14can be hidden or it can be disabled there multiple options are there there multiple reasons are there
- 16:20so element is there it is there in the Dom but we are not able to interact this suppose if it
- 16:27is input box we are not able to pass the value if it is a button we are not able to click on
- 16:31the button so we're not able to interact with the element maybe it is a hidden element or it may be
- 16:38disable State we don't know so in multiple cases you will get element not interactable exception
- 16:44so what is the solution again we can put in the TR catch block click on the element and element
- 16:49not interactable exception and provide the message how we can solve this there are three
- 16:53different ways we can solve this problem element not interactable first thing using explicit
- 16:59wait we can solve because we are waiting here till the element is clickable or till element to
- 17:04be clickable and then get the element perform the click this is one solution if it is didn't work
- 17:11then you can go with the make the element visible first and the same solution we have used for
- 17:17disable this hidden elements also same solution may work here so first make the element is visible
- 17:23on the Dom and then perform the click action this is one solution using JavaScript executor if it
- 17:29is a hidden you can apply this solution suppose if it is a disabled State okay and then you can
- 17:35use JavaScript execut so this is another solution okay so these are the different three solutions
- 17:41which we have to solve element not intractable exception next no such attribute exception no
- 17:51such attribute exception sometimes we are trying to get some value of the attribute of the element
- 17:56for example let's say uh just now we have seen so I just capture one element from that element I'm
- 18:02trying to get some attribute it can be name or ID placeholder whatever and based on the value I want
- 18:08to do some task sometimes if the attribute is not available for the element but still you are trying
- 18:14to get the value of the attribute then you'll get a no such attribute exception so Throne when
- 18:20trying to retrieve an attribute from the element but the attribute does not exist okay suppose I'm
- 18:28I want to capture the value of the name attribute I have written get attribute of name but name is
- 18:33not available for the attribute then you will get a no such attribute exception again that you can
- 18:39put inside the tri Tri block and if that that will throw exception then by using catch block
- 18:45you can put no such attribute exception and provide the proper message to the user this
- 18:50is no such attribute exception using T cat block we can handle next one no such window exception
- 18:59no such window and this exception we will get mostly we will work with the multiple windows
- 19:04or multiple tabs we have a switching Command right switch. new window switch. window so while working
- 19:11with those methods we will get no such window exception so Throne when trying to switch to
- 19:16window that does not exist so if you got window ID or handle value and by using the handle you trying
- 19:23to switch to the particular window but by the time that window is got closed by some reason so then
- 19:29you will get a no such window exception so you're trying to switch to some window suppose you have
- 19:33open two windows one is parent and child window and you have successfully switched to the child
- 19:38window and by mistake you closed your parent window now again you trying to switch back to
- 19:43the parent window in that scenario you will get a no such window exception if the window is not
- 19:50available but still you're trying to switch to it in that case you'll get a no such window exception
- 19:55so in that case put that in the tri block switch to window and in the catch block write a small
- 20:01message to the user window is not found so the program will not be terminate unexpectedly so it
- 20:06will properly terminate the program properly exit from the program this is no such window exception
- 20:12and belongs to Windows similarly there is same kind of exception is there for frame no such frame
- 20:19exception no such frame again same reason suppose I'm trying to switch to particular frame but the
- 20:26frame is does not exist so then you will get a no such frame exception I'm trying to switch to the
- 20:32frame but the frame itself is does not exist on the page then you will get a no such frame
- 20:37exception and again you can put that command in the tri block and in the catch block you can write
- 20:42no such frame exception and provide message to the user no such frame exception and same thing for we
- 20:50have for alert also no alert present exception no alert present exception so when you will get this
- 20:57occur when trying to inter interact with the alert that does not exist suppose I just want to capture
- 21:03the alert then I want to close it for example so you trying to switch to it once you get alert then
- 21:10you can accept it but suppose this is not able to get the alert why because the alert itself
- 21:16is not available that doesn't exist if it is exist then you are able to switch to alert then you can
- 21:21accept it but the alert itself is not exist then how come this switch. alert will get the alert
- 21:26to you it cannot get so in that case you will get a no alert present exception and again same thing
- 21:32we can put that command in the tri block and uh if it is through exception then catch block you can
- 21:38handle this no alert present exception you can provide proper exception name and then provide
- 21:44message to the user so this is no alert present except three exceptions are almost similar no such
- 21:51window exception no such frame exception no such sorry no alert present exception so these three
- 21:59Comm exceptions will related to window frame alert okay if they are not exist till we are
- 22:06trying to switch to them then you'll get these exceptions next one UNH handle alert exception
- 22:14UNH handle alert exception it is also related to alert so when you'll get this it thrown when
- 22:21there is unhandled alert preventing web driver from interacting with the page that means what
- 22:27attempting to click on element while an alert is open see whenever you get an alert will you
- 22:33able to do any other activity till you close that alert window you cannot proceed further
- 22:39right so suppose the alert is available but still you are trying to do some other action
- 22:45without closing the alert in that case we will get an exception okay so how to handle this we
- 22:52can put the switching command and accept command in the triag block and then if it is thrown UNH
- 22:58handle alert exception then you can provide proper message to the user so thr when there is unhandled
- 23:04alert preventing web driver from interacting with the web page attempting to click on element while
- 23:11alert is open then you'll get an unhandled alert exception next one this is Mo Mouse related action
- 23:20move Target out the bonds exceptions so most of the times you will get this exception when you
- 23:24do mouse actions move Target out of exception so when this exception occurs suppose you are
- 23:32trying to move your mouse outside of the visible screen area so suppose you are in the web page
- 23:39you want to do some M over action you provide proper element suppose if the element is out of
- 23:45the scope or suppose if there is a slider right in the slider you want to move the slider from
- 23:51one place to X2 J or J to X some horizontal or vertical and if you're providing the pixel number
- 23:58more than the size then you are going out of the bond so you'll get this exception move
- 24:04Target out of the bond suppose the slider size is let's say 0 to 100 and you are trying to move to
- 24:10125 for example or 150 you are going out of bound exception you're going to out of bound the range
- 24:16so then you will get this exception move Target out of bound exception occurs when trying to move
- 24:22the mouse outside of the visible screen area and this will throw exception whenever you move to
- 24:28element to perform you will get an exception so better to keep this in the tri block everything
- 24:34and if you got more Target outut of bond exception then you can provide proper message to the user to
- 24:40the catch block this is more Target Auto Bond exception next screenshot exception so you'll
- 24:49get this exception when you're working with the capturing the screenshots suppose you are trying
- 24:53to capture the screenshot from the page but at the time it is got minimized for ex sample then
- 25:00it will fail to capture the screenshot because whenever you want to capture the screenshot the
- 25:04page should be visible properly okay so sometimes it may be visible or sometimes it is minimized
- 25:12it is not visible in that case it if it is not properly captured the screenshot then you will
- 25:18get this exception screenshot exception so that is the reason whenever you're trying to capture
- 25:23the screenshot and doing copy and everything you put that in the tri block and in the catch block
- 25:28handle the screenshot exception if it is able to capture the screenshot that's still fine if it is
- 25:33not able to capture then you will able to handle the Exception by providing track catch blog this
- 25:40is related to screenshot exception now invalid selector exception this is also very commonly uh
- 25:48we get this exception invalid selector exception it's very simple suppose you have written some uh
- 25:55find element by. XO or css or ID what whatever and you especially related to expath and CSS
- 26:02invalid selector exception is especially related to expath and CSS and suppose you have created
- 26:08some incorrect xath or incorrect CSS then you will get invalid selector exception incorrect
- 26:16in the sense what syntactically incorrect suppose instead of using two slashes you have used only
- 26:23one single SL forward slash and instead of keeping single code you suppose you forgot to
- 26:28put double quotations in the bracket so if expath CSS syntax is correct in syntax is incorrect then
- 26:36you will get invalid selector exception so most of the times we will check xath and CSS uh in
- 26:41selector Hub whether they're properly trying to locate element or not then we will use them in
- 26:47our automation skript most of the time we don't directly use in our automation skript so there
- 26:51are very less number of chances are there to get this exception but sometimes by copy pasting if
- 26:57you miss something if you miss some syntax then you will get invalid selector exception especially
- 27:01for expath and CSS okay now safe side what we can do is we can put that locator in the tri block and
- 27:11if it is thrown invalid selector exception then can handle with the catch block just providing
- 27:16message to the user that is invalid selector exception if xath is syntactically incorrect
- 27:23or css is also syntactically incorrect then you will get invalid selector exception now next one
- 27:33invalid session ID exception invalid session ID exception so what is session ID means what is
- 27:42the session ID so whenever you trying to launch or whenever trying to create a driver instance
- 27:50like whenever you say driver equal to web driver driver equal to new Chrome driver you're creating
- 27:55the object for Chrome driver right so that time the session will be created one session will be
- 28:01created Chrome browser session or edge browser session or Firefox browser session will be created
- 28:07so when you will get invalid session ID exception suppose when you're trying to use web driver after
- 28:13session has been terminated you are trying to use web driver after session has been terminated for
- 28:20example let's say web driver driver equal to new Chrome driver you created so that will actually
- 28:24create the session and immediately you you quit it or close it after that you're trying to do
- 28:31some activity so before doing activity itself you already quitting from the browser already quitting
- 28:37from the brow closing the browser so obviously when I use close or quit command what will happen
- 28:43session will be closed so the session ID no longer available so in that case you will get
- 28:49a invalid session exception if the session is not available that is already session ID is closed by
- 28:55quit or close command but still you are trying to interact with the page your element then you will
- 28:59get invalid s exception so once you created your driver instance you should not close it till you
- 29:07complete your activities or till you completed all the actions on the page okay so by mistake
- 29:13if you close the page and then you are trying to do some activity means you will get invalid
- 29:17session exception so that is the reason you can just try to put driver. get inside the tri triy
- 29:23block whenever you're launching the page put that in the Dy block and in the cash block Cas invalid
- 29:29session exception and then you can provide message to the user this is invalid session ID exception
- 29:39next one timeout exception and this is especially related to uh explicit weight time out exception
- 29:47explicit weight so normally implicit weight also we specify the time right but implicit
- 29:53weight is applicable for all the elements so if the suppose I'm looking for some element
- 29:58and let's say I in implicit we I put 10 seconds maximum and element is not available within 10
- 30:06seconds so obviously you will get an exception related to Element no such element exception
- 30:11something like this but you won't get timeout exception there but in case of explicit weight
- 30:18also we will specify the time right in explicit weight but how we will use this explicit weight by
- 30:24putting proper condition let's say I written like this expected conditions do visibility of element
- 30:30located some element I provided also I put some conditional method suppose within this particular
- 30:37time this condition should be satisfied if this condition is not satisfied within 10 seconds
- 30:43then time out exception will come it is based on the condition and time but in implicit weight we
- 30:48don't put any condition so obviously that will throw exception implicit weight will not throw
- 30:54time out exception but only explicit weight will throw time out exception so if the condition is
- 31:00not satisfied within this time then you will get a timeout exception which is related to explicit
- 31:08weight so safe side what we can do these weight statements also we can put in the trage Block in
- 31:14case if there is an timeout exception we can handle properly using catch block and we can
- 31:19exit the program properly without terminating it so element not found within the time limit you can
- 31:24just provide proper message to the user and then you can exit from the program so this is Timeout
- 31:29exception so timeout exception is basically related to what explicit weight or fluent weight
- 31:36not related to uh implicit weight okay next one insecure certification exception this is related
- 31:47to SSL certification what is SSL means SSL secure socket layer so through when selum is unable to
- 31:57verify certificate of the yeah secure socket layer so unable to verify the SSS certificate
- 32:04of the website with an insecure connection so normally if I open any website which is not
- 32:10having SSL certificate or invalid certificate so then what happens by default you will get an
- 32:16exception insecure certificate exception you will get but to avoid that exception what we can do we
- 32:24configure that in the Chrome options right in the Chrome options we can pass these parameters we can
- 32:30create a chrome options class and in option there is a method called set accept insecure
- 32:34certificates make it as a true in that case the exception we can avoid insecure certificate
- 32:40exception we can avoid but if you're not handling this for example it's not handling this there is
- 32:46no SSL certificate valid then definitely you will get an exception but if you still want to
- 32:53continue with that website with with By ignoring CER SSL certificate then you can say options do
- 32:59set accept insecure certification make it is true and pass the options object in the driver
- 33:06so that will solve the problem okay so this is insecure certificate exception related to SSL next
- 33:14one invalid argument exception invalid argument exceptions Okay so
- 33:28in implicit weight or explicit weight can we pass negative time time in negative value no
- 33:34time cannot be a negative value right so when you pass a negative value that is obviously invalid
- 33:40argument so duration of half seconds should accept only integers but here I'm passing minus 10 even
- 33:47it can be implicit we or it can be explicit we whatever basically it is invalid argument it is
- 33:52not accepting so that case that will throw invalid argument exception so whenever you using implicit
- 33:59weight also all explicit weight keep them also in TR cach Block in case any issue comes that will
- 34:05through exception invalid uh argument exception you will get and you can provide message to the
- 34:10user so we cannot give the invalid values here we don't give it because we know but sometimes
- 34:18if there is any Mistake by mistake if unknowingly if you provide any negative value then you will
- 34:22get a invalid argument exception next one web driver exceptions most of the times you'll
- 34:30get this whenever you start running your skit immediately you will get this first of all it
- 34:35will not launch browser itself immediately you will get web driver exception so when you will
- 34:40get this web driver exception most of the times exception Throne when something goes wrong while
- 34:47interacting with the driver while interacting with the driver or when you're creating the
- 34:53driver instance if something is go goes wrong then you'll get a web driver exception so what
- 34:58could be the reasons maybe the browser versions are not compatible okay suppose you using the old
- 35:06Chrome version or you are using latest Chrome version then there is no compatibility right
- 35:12and similarly if you're using latest version of selenium but browser is very old then again no
- 35:16compatibility browser is latest but we are using very old version of selenium so then also there is
- 35:22no compatibility so in that case if there is any conflict between your driver and your browser you
- 35:28will get a web driver exceptions so at the time of creating web driver driver equal to new Chrome
- 35:34driver so you will that will not execute first of all the driver creation itself will fail in
- 35:40that case you will get a web driver exception so better to keep those statements in the TR
- 35:44catch block itself if there is any problem you can safely exit from the program without interruption
- 35:50so web driver exception you can put in the catch block you can provide General web driver exception
- 35:54is occurred and again you need to check all the versions and properly aled or not then you can
- 36:00fix that so this is web driver exception if web driver exception comes your script will
- 36:05not continue first of all even the browser itself will not launch if you have web driver exception
- 36:11because at the time of creating the driver itself you have some issue with that this is web driver
- 36:18exception next one session not found exception session not found exception and this is also again
- 36:28same kind of a scenario previously we have seen invalid session exception same thing related to
- 36:33this suppose you have quit from the browser but still you are trying to do some activity
- 36:38see here I have quit from the browser already but still I'm trying to use the same driver instance
- 36:43will it work no session has already ended by quit command so this will not work so this will throw
- 36:49session not found exception session not found exception so make sure to check if the session
- 36:55is still active before performing the operations or handle the exceptions so whenever you do some
- 37:02activities you have to check the session is still alive then only can do that okay so keep the whole
- 37:08code in TR the inside the TR catch block if it is got failed session is not available or session
- 37:15not exception through then catch block you can specify that exception and provide message to
- 37:19the user session is already closed or session is not found something like that so this is another
- 37:26exception session not found exception these are small exceptions but by mistake unknowingly we
- 37:32will do certain things so because of that we will get these kind of exception but most of the times
- 37:36nobody will do right after repeting the browser will you do any activity no right most of the
- 37:41times we don't do that but unknowingly sometimes it will happen so in that case you'll get a
- 37:47session not found exception so better to keep inside the tri block also then you can put proper
- 37:52message in the catch block so session not found exception so when you will get this exception
- 38:00so when you do some activity after quitting the browser after quitting the browser means session
- 38:06is already closed then you will get a session not found exception next one I think this is the last
- 38:13exception now there is a small clue here guys suppose you don't know the exception name but you
- 38:20still want to use TR catch or still you want to handle the exception properly then what you can do
- 38:24you can put the entire code in the TR catch block that ly and you can specify different type of
- 38:30elements or different type of exception one group let's say no such element or St element reference
- 38:36exception or element not interactable exception so like this you can put different type of exceptions
- 38:43and then you can put proper message to the user so this is also the general way to handle the
- 38:50exception so better to keep all the statements in proper Tri blocks and handle them by Pro
- 38:55providing proper exception option names through catch block but some exceptions we can solve by
- 39:01using JavaScript executor or web driver weight but certain exceptions we cannot solve because that is
- 39:07problem with the application not from the side not from our side okay for example let's say there is
- 39:12a button which is disabled state by default it is a disabled and if you're trying to perform some
- 39:17action how it is possible so the developer should enable that button then our script will work so in
- 39:23that case we cannot solve we simply exit the code without elmination but suppose element is there
- 39:29in the page but somehow it is hidden in that case we can make it available make it visible
- 39:35then we can perform the action forcefully we can do using JavaScript executor that will solve the
- 39:40problem so certain things will solve the problem certain things may not solve the problem similarly
- 39:45element click intercepted exception so when you will get element click intercepted exception the
- 39:51element is there but you are not able to click on that element especially this will happen
- 39:55for checkboxes radio buttons links buttons so element click intercepted exception when you'll
- 40:00get sometimes the elements are overlapping and sometimes the page is minimizing or maximizing
- 40:06that resolution changes because of Click may not work on the element properly so then you can do
- 40:12that forcefully using JavaScript executor and if you're doing some activity using JavaScript
- 40:17executor what does it mean you're trying to do the same activity forcefully through JavaScript
- 40:22executor we're trying to inject the JavaScript executor statement directly inside the browser
- 40:27so not through web driver so through web driver we are trying to execute the JavaScript statements
- 40:33directly on the browser but normally what happens we are running the web driver methods or commands
- 40:39and through web driver method apis will be interacted with the browser through JavaScript
- 40:43so in instead of interacting the browser through web driver API we are directly interacting with
- 40:48the browser elements through JavaScript executor so that's how we can solve certain problems but
- 40:54every problem is not solved okay for example let's say I have written proper locator but the element
- 41:01itself is not visible on the page element not visible exception will get ele no such element
- 41:07exception will get can we solve that problem no until unless the developer plays the element
- 41:11on the page we cannot do that so simply we can put that element in the TR cat block and proper
- 41:17message you can just write and exit from the code without termination and spect can just exit
- 41:22from the code because the element itself is not there in the page how we can perform the action
- 41:27so certain things we can solve through JavaScript executor or web driver weights but certain things
- 41:32we cannot solve similarly stale element exception stale element reference exception so whenever you
- 41:38refresh the page or reload the page you will get stale element exception so developer no need to do
- 41:43anything with that we need to handle this because we are refreshing the page multiple times there is
- 41:48a requirement to refresh the page so you need to handle that using JavaScript executor or by using
- 41:54explicit weight statement okay so these are all common exceptions most of the times we will get
- 42:0120 types of exceptions have listed out there are n number of exceptions but difficult to remember
- 42:06each and every at least five to six exceptions if you remember easily you'll able to address them
- 42:11in the interview point of view okay so that's all for exception web driver exceptions concept okay
- 42:20yeah that's all for today's session we'll stop here
About this transcript
This page contains the full transcript of Selenium Java Coding Tips & Tricks #13 |Selenium WebDriver Common Exceptions by SDET- QA, generated from the public captions YouTube serves with the video. The transcript has 7,272 words across 417 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.