YouTube2Text

Selenium Java Coding Tips & Tricks #13 |Selenium WebDriver Common Exceptions — Transcript

by SDET- QA · 7,272 words · 417 segments · language en · Watch on YouTube

Full transcript

  1. 0:00yeah all right so today we are going to see  uh one of the most important concept common
  2. 0:09linear web driver exceptions so we will get  common exceptions most of the time web driver
  3. 0:14exceptions when you're writing automation  test scripts or when you're running your
  4. 0:18automation test scripts we will commonly get  some kind of exceptions so what is the main
  5. 0:23objective of exception so why we'll get an  exception why we'll get an exception normally
  6. 0:31because of some input is not valid then uh we'll  get some exception so what is the purpose of uh
  7. 0:37concept of exception handling what's the main  concept of exception handling suppose if there
  8. 0:42is any exception so we should not make our code or  script terminate immediately so instead of that we
  9. 0:48need to prop we need to provide a proper message  uh then we will exit from the code so we should
  10. 0:55not immediately terminate the code with proper  message we need to exit from the code whenever you
  11. 1:01get some exception so that is the main objective  of using exception handling right even selenium
  12. 1:07also there are different type of exceptions are  there so we will discuss one by one around 15 to
  13. 1:1220 exceptions are there which are very commonly uh  we will see while executing our test or framework
  14. 1:19and first we'll see what is that exception name  and when you will get that type of exception
  15. 1:24and how we can handle that exception the first  one knows a such element exception so very very
  16. 1:30common exceptions many times we have seen this  exception no such element exception so what is no
  17. 1:36such element exception when you will get it occurs  when an element with the special specified locator
  18. 1:42cannot be found in the Dom so for example what  let's say I provided one locator let's say by.
  19. 1:48ID some ID or some name or some xath I provided  but with that uh with this particular attribute
  20. 1:55or with this xath or with this CS there is no  element available in the web page in that case
  21. 2:01you will get a no such element exception so trying  to interact with the element that doesn't exist on
  22. 2:06the web page itself so whatever the locator you  passed here corresponding element itself is not
  23. 2:12available in the web page so in that particular  case you will see no such element exception okay
  24. 2:19so suppose when you write statement like this  suppose here the ID is not available or xath or
  25. 2:25CS is not available the xath ID name you have used  is correctly written but but the corresponding
  26. 2:30element is not available the element itself is  not available so in that case you will get a no
  27. 2:36such element exception so how we can handle this  so normally you can put in the TR catch block so
  28. 2:43you can put that element in the tri catch block  and in the catch block you can say no such element
  29. 2:47exception and simply provide a message to the  user like element not found along with the proper
  30. 2:53message okay and uh sometimes maybe the element  takes some time to load on the web page page so
  31. 3:00you can also wait for the element for some time  let's say you can use web driver weit like this
  32. 3:05and wait until expected conditions do presence  of element located and then pass the locator
  33. 3:11and it will wait for the element and once it is  present on the web page then it will return the
  34. 3:16web element and then it will continue the process  but even after 10 seconds if the element is not
  35. 3:22available me then again you'll get the timeout  exception then because we use web driver weight
  36. 3:28also right even web driver weight is also exceeded  the time so then you will get the time out
  37. 3:32exception okay sometimes we can handle through web  driver weight even web driver weight is also not
  38. 3:38able to solve means there is some problem with the  element so that element is not available so this
  39. 3:44is how we can handle it we can put the TR catch  block the element locator along with this we can
  40. 3:49put Tri block and catch block we can just simply  provide the message to the user so that is no such
  41. 3:55element exception so when you will get this if the  locator is correct but corresponding element is
  42. 4:01not available or not present on the web page then  you will get no such element exception you need to
  43. 4:08remember guys because in interview definitely they  will ask some kind of exceptions at least four
  44. 4:13to five exceptions you need to remember very very  important and whatever exceptions I have noted in
  45. 4:19this document all are important 15 to 20 types  of exceptions very frequently we'll get these
  46. 4:25exceptions you should remember them now the next  exception is element not visible exception this
  47. 4:31is another type of exception element not visible  exception so when this will occur it occurs when
  48. 4:38element is present in the Dom but it is not  visible on theb page okay you understood my
  49. 4:45point element is present in the Dom but it is not  visible and what kind of element it is it is there
  50. 4:54in the DM but it is not visible on the page this  is basically hidden element right hidden element
  51. 5:00so occurs when element is present in the DM  but it's not visible on the web page then you
  52. 5:05will get a element not visible exception so  normally we will capture the element and then
  53. 5:11we will try to perform the action click action  then you will get this exception identifying the
  54. 5:16element is working fine but when you perform the  action it is not visible so you'll get element
  55. 5:23not visible exception right so how we can handle  this normally so whenever you get an element first
  56. 5:30verify the status okay if it is displayed then  click on the element okay if it is not displayed
  57. 5:37obviously it will throw exception so we need to  handle that in the catch block element not visible
  58. 5:41exception and provide the proper message to the  user element is not visible sometimes even though
  59. 5:48it is not visible on the web page we can make it  visible forcefully and then we can perform the
  60. 5:53action using JavaScript executor it is possible  so how we can make it visible Js JavaScript execut
  61. 6:00execute script arguments of zero style. display.  block element whatever element we are looking for
  62. 6:06can pass the element and this par statement will  make our element visible on the page after it is
  63. 6:13visible then we can perform the click action so  most of the times this solution will solve it
  64. 6:19especially when you have hidden elements so  the elements are present in the DM but they
  65. 6:23are not visible on the web page so we can make  those elements visible using JavaScript executor
  66. 6:30and then we can perform the click action so  this will solve the problem and we can also
  67. 6:35handle this using TR catch block suppose if you  don't if you're not using JavaScript executor so
  68. 6:39definitely that will throw exception so you can  handle the exception using TR catch block but if
  69. 6:44you're using JavaScript executor it will able  to handle it then you don't need to use TR C
  70. 6:48block so this is element not visible exception now  third one stale element reference exception stale
  71. 6:59element reference exceptions very very important  and very popular exception stale element reference
  72. 7:06exception so when you will get this the exception  is thrown when an element is no longer attached to
  73. 7:12the DM usually after a page update or refresh very  very important exception guys suppose you captured
  74. 7:22some element and you have performed some action  immediately it is working fine but after writing
  75. 7:28some piece of code suppose you have written some  piece of code for loading page or refreshing the
  76. 7:32page after that again if you're trying to perform  or after that you're trying to locate this element
  77. 7:38then you'll get a stale element refer exception  so stale is nothing but what whenever you refresh
  78. 7:44the page or whenever you update your page the  element becomes stale so the locator may not
  79. 7:50work so you need to again locate the element  one more time so how we can handle this we need
  80. 7:55to just relocate the element one more time we  need to write a locator for example let's say
  81. 8:00here I have located my element and when performing  the action it is throwing stale element reference
  82. 8:05exception so immediately in the catch block what  you need to do again relocate the same element
  83. 8:10write the whole thing again one more time and  then perform the action so this will solve the
  84. 8:15problem stale element reference exception can  be solved by relocating the element once again
  85. 8:21because whenever you refresh the page or whenever  you update the page or reload the page the same
  86. 8:26locator may not work one more time time so you  need to again keep on uh Rite the same locator
  87. 8:33one more time that is stale element reference  exception steel element reference exception
  88. 8:42so let me give you an example so when it will  happen normally most of the times you will see
  89. 8:48this exception let's say uh this is my automation  script let's say in the first place here I have
  90. 8:53located my element this is my element okay and my  element is here now I have done some activity here
  91. 9:01and here my I refreshed my page and again this  element I'm trying to use it here so then what
  92. 9:08happens we will get a stale element reference  exception because you have done some update or
  93. 9:14you have done some refresh after locating this  element so here what you need to do again you
  94. 9:19need to write a locator here one more time you  need to locate the element and then you will
  95. 9:23get the you can continue the action so that  you can do using TR catch block so this say
  96. 9:29stale element reference exceptions whenever you  refresh the page or whenever you update the page
  97. 9:35the element becomes stale so in that case you  will get a stale element exception what is the
  98. 9:40solution for this you just relocate the element  in the catch block next one invalid element State
  99. 9:47exception invalid element State exception so when  it will thrown when attempting to interact with a
  100. 9:57element that cannot be interact Ed with such as  disabled form field entering text into disabled
  101. 10:04text field very important most of the times  it will happen suppose invalid element State
  102. 10:12exception invalid element State exception let's  say you have some input box and currently it is a
  103. 10:19disabled State you you can't enter any value but  still you are entering the value by using send
  104. 10:24Keys method so because it is a disable it cannot  it is not allowed to to provide any value into
  105. 10:30it so in that case you will get invalid element  State exception currently the state of element is
  106. 10:36not ready to accept the data or accept the value  so in that case we'll get a invalid element State
  107. 10:44exception if it is enabl then only we can pass  or we can interact with the element not only
  108. 10:49input box in case of buttons also sometimes it  will happen suppose button is a disabled but you
  109. 10:54trying to click on that button in that case  also you'll get invalid element State except
  110. 11:00so first of all before performing any action  on the element that element should allow us
  111. 11:03to perform the action it can be click or can send  Keys whatever so otherwise it will throw invalid
  112. 11:10element State exception so for example here  I have taken some input field and I'm passing
  113. 11:15the send Keys method if it is a disable then  the send Keys method will throw invalid stale
  114. 11:20element exception so again how we can handle this  sample we can put the tri catch block so we can
  115. 11:26just put the input field in the tri block and  pass this value if it is through an exception
  116. 11:31catch block you can handle this invalid element  State exception and just provide the message to
  117. 11:36the user like cannot interact with the element  because it is disabled something like that it
  118. 11:41can provide some user defined message to the user  okay so this is invalid element State exception
  119. 11:48if the element is disabled if you are trying to  perform some action on that element then you will
  120. 11:53get an invalid element State exception this is one  more important thing now next one element click
  121. 12:02intercepted exception this is also very common  exception most of the times we have seen this
  122. 12:07element click intercepted exception element click  intercepted exceptions occur when another element
  123. 12:15abstract The Click action another element abstract  The Click action element click this exception is
  124. 12:22specifically for clicking when you're clicking  on checkbox or when you're clicking on the radio
  125. 12:27button or when you're clicking on the button or L  you will get element click intercepted exception
  126. 12:32so when you will get these exceptions suppose uh  you have some web page and you are trying to click
  127. 12:40on this link or button and you have S you have  written code properly and it is trying to click on
  128. 12:46this but when you're launching the page sometimes  the page is not maximized sometimes page is small
  129. 12:53size page is open okay and sometimes elements is  overlapped in that case what happens the another
  130. 13:00element will abstract The Click action so it is  not allowing to click on the particular element
  131. 13:06maybe the because of overlapping because of the  size of the page it is not allowing us to click on
  132. 13:11that element so in that case you will get element  click intercepted exception it is basically
  133. 13:17interrupted The Click action so element click  intercepted exception you will get whenever the
  134. 13:24another element abstract The Click action so for  example I have located a button element I'm just
  135. 13:30performing The Click so if any other element is  overlapped or any other element is disturbing the
  136. 13:35process or thing then you'll get this exception  it's not allowing to perform the click action
  137. 13:40then how we can handle this you can put in the  try catch block so try button in the try you can
  138. 13:45capture the button perform the click if it is not  able to click element clicker interception will be
  139. 13:49return and then you can provide proper message to  the user but how we can handle this suppose this
  140. 13:56is not problem of user actually so we can still  handle how we can handle using explicit weight
  141. 14:02or JavaScript executor we can use so most of the  times we can solve this element cck intercepted
  142. 14:07exception either by using explicit weight or by  writing JavaScript executor there are two methods
  143. 14:12are there to solve this problem first method  using explicit weight so you can just create a
  144. 14:19a web driver weight explicit weight and wait until  element to be clickable this is the conditional
  145. 14:25method we have to use so once the element is able  to click if the condition matches then we can
  146. 14:31perform the click action so mostly this will solve  the problem element click intercepted exception
  147. 14:38okay so in case even explicit weight is also not  able to solve then you can use JavaScript executor
  148. 14:44approach so JavaScript executor definitely will  solve the problem because we are internally
  149. 14:49directly executing the JavaScript instead of  inter instead of running the web driver command
  150. 14:55so js. execute script arguments of zero means what  what whatever element we are passing here that is
  151. 15:01stored in arguments of zero then we are performing  The Click action through JavaScript executor so
  152. 15:06element so element click intercepted exception  we can solve either by using explicit weight
  153. 15:15or by using JavaScript executor okay and if you  still want to handle this then you can again put
  154. 15:22in the tri catch block okay so uh in the cat block  directly you can put the solution okay so if it is
  155. 15:31throw exception then alternative you can try with  explicit weight alternate you can put Javascript
  156. 15:35executor that you can put in the catch block that  will automatically solve the problem so element
  157. 15:40click intercepted exception when you will get  this exception if any element any other element
  158. 15:46interrupt the process or interrupt The Click  action or interrupt any other action you will get
  159. 15:51a element click Interceptor exception most common  exception next element not intractable exception
  160. 16:02sometimes you'll get this inter element not  intractable when this will occur when the element
  161. 16:08present in the DM the element is present in the  DM but it is not in the state to be interacted it
  162. 16:14can be hidden or it can be disabled there multiple  options are there there multiple reasons are there
  163. 16:20so element is there it is there in the Dom but  we are not able to interact this suppose if it
  164. 16:27is input box we are not able to pass the value  if it is a button we are not able to click on
  165. 16:31the button so we're not able to interact with the  element maybe it is a hidden element or it may be
  166. 16:38disable State we don't know so in multiple cases  you will get element not interactable exception
  167. 16:44so what is the solution again we can put in the  TR catch block click on the element and element
  168. 16:49not interactable exception and provide the  message how we can solve this there are three
  169. 16:53different ways we can solve this problem element  not interactable first thing using explicit
  170. 16:59wait we can solve because we are waiting here  till the element is clickable or till element to
  171. 17:04be clickable and then get the element perform the  click this is one solution if it is didn't work
  172. 17:11then you can go with the make the element visible  first and the same solution we have used for
  173. 17:17disable this hidden elements also same solution  may work here so first make the element is visible
  174. 17:23on the Dom and then perform the click action this  is one solution using JavaScript executor if it
  175. 17:29is a hidden you can apply this solution suppose  if it is a disabled State okay and then you can
  176. 17:35use JavaScript execut so this is another solution  okay so these are the different three solutions
  177. 17:41which we have to solve element not intractable  exception next no such attribute exception no
  178. 17:51such attribute exception sometimes we are trying  to get some value of the attribute of the element
  179. 17:56for example let's say uh just now we have seen so  I just capture one element from that element I'm
  180. 18:02trying to get some attribute it can be name or ID  placeholder whatever and based on the value I want
  181. 18:08to do some task sometimes if the attribute is not  available for the element but still you are trying
  182. 18:14to get the value of the attribute then you'll  get a no such attribute exception so Throne when
  183. 18:20trying to retrieve an attribute from the element  but the attribute does not exist okay suppose I'm
  184. 18:28I want to capture the value of the name attribute  I have written get attribute of name but name is
  185. 18:33not available for the attribute then you will get  a no such attribute exception again that you can
  186. 18:39put inside the tri Tri block and if that that  will throw exception then by using catch block
  187. 18:45you can put no such attribute exception and  provide the proper message to the user this
  188. 18:50is no such attribute exception using T cat block  we can handle next one no such window exception
  189. 18:59no such window and this exception we will get  mostly we will work with the multiple windows
  190. 19:04or multiple tabs we have a switching Command right  switch. new window switch. window so while working
  191. 19:11with those methods we will get no such window  exception so Throne when trying to switch to
  192. 19:16window that does not exist so if you got window ID  or handle value and by using the handle you trying
  193. 19:23to switch to the particular window but by the time  that window is got closed by some reason so then
  194. 19:29you will get a no such window exception so you're  trying to switch to some window suppose you have
  195. 19:33open two windows one is parent and child window  and you have successfully switched to the child
  196. 19:38window and by mistake you closed your parent  window now again you trying to switch back to
  197. 19:43the parent window in that scenario you will get  a no such window exception if the window is not
  198. 19:50available but still you're trying to switch to it  in that case you'll get a no such window exception
  199. 19:55so in that case put that in the tri block switch  to window and in the catch block write a small
  200. 20:01message to the user window is not found so the  program will not be terminate unexpectedly so it
  201. 20:06will properly terminate the program properly exit  from the program this is no such window exception
  202. 20:12and belongs to Windows similarly there is same  kind of exception is there for frame no such frame
  203. 20:19exception no such frame again same reason suppose  I'm trying to switch to particular frame but the
  204. 20:26frame is does not exist so then you will get a no  such frame exception I'm trying to switch to the
  205. 20:32frame but the frame itself is does not exist  on the page then you will get a no such frame
  206. 20:37exception and again you can put that command in  the tri block and in the catch block you can write
  207. 20:42no such frame exception and provide message to the  user no such frame exception and same thing for we
  208. 20:50have for alert also no alert present exception no  alert present exception so when you will get this
  209. 20:57occur when trying to inter interact with the alert  that does not exist suppose I just want to capture
  210. 21:03the alert then I want to close it for example so  you trying to switch to it once you get alert then
  211. 21:10you can accept it but suppose this is not able  to get the alert why because the alert itself
  212. 21:16is not available that doesn't exist if it is exist  then you are able to switch to alert then you can
  213. 21:21accept it but the alert itself is not exist then  how come this switch. alert will get the alert
  214. 21:26to you it cannot get so in that case you will get  a no alert present exception and again same thing
  215. 21:32we can put that command in the tri block and uh if  it is through exception then catch block you can
  216. 21:38handle this no alert present exception you can  provide proper exception name and then provide
  217. 21:44message to the user so this is no alert present  except three exceptions are almost similar no such
  218. 21:51window exception no such frame exception no such  sorry no alert present exception so these three
  219. 21:59Comm exceptions will related to window frame  alert okay if they are not exist till we are
  220. 22:06trying to switch to them then you'll get these  exceptions next one UNH handle alert exception
  221. 22:14UNH handle alert exception it is also related  to alert so when you'll get this it thrown when
  222. 22:21there is unhandled alert preventing web driver  from interacting with the page that means what
  223. 22:27attempting to click on element while an alert  is open see whenever you get an alert will you
  224. 22:33able to do any other activity till you close  that alert window you cannot proceed further
  225. 22:39right so suppose the alert is available but  still you are trying to do some other action
  226. 22:45without closing the alert in that case we will  get an exception okay so how to handle this we
  227. 22:52can put the switching command and accept command  in the triag block and then if it is thrown UNH
  228. 22:58handle alert exception then you can provide proper  message to the user so thr when there is unhandled
  229. 23:04alert preventing web driver from interacting with  the web page attempting to click on element while
  230. 23:11alert is open then you'll get an unhandled alert  exception next one this is Mo Mouse related action
  231. 23:20move Target out the bonds exceptions so most of  the times you will get this exception when you
  232. 23:24do mouse actions move Target out of exception  so when this exception occurs suppose you are
  233. 23:32trying to move your mouse outside of the visible  screen area so suppose you are in the web page
  234. 23:39you want to do some M over action you provide  proper element suppose if the element is out of
  235. 23:45the scope or suppose if there is a slider right  in the slider you want to move the slider from
  236. 23:51one place to X2 J or J to X some horizontal or  vertical and if you're providing the pixel number
  237. 23:58more than the size then you are going out of  the bond so you'll get this exception move
  238. 24:04Target out of the bond suppose the slider size is  let's say 0 to 100 and you are trying to move to
  239. 24:10125 for example or 150 you are going out of bound  exception you're going to out of bound the range
  240. 24:16so then you will get this exception move Target  out of bound exception occurs when trying to move
  241. 24:22the mouse outside of the visible screen area and  this will throw exception whenever you move to
  242. 24:28element to perform you will get an exception so  better to keep this in the tri block everything
  243. 24:34and if you got more Target outut of bond exception  then you can provide proper message to the user to
  244. 24:40the catch block this is more Target Auto Bond  exception next screenshot exception so you'll
  245. 24:49get this exception when you're working with the  capturing the screenshots suppose you are trying
  246. 24:53to capture the screenshot from the page but at  the time it is got minimized for ex sample then
  247. 25:00it will fail to capture the screenshot because  whenever you want to capture the screenshot the
  248. 25:04page should be visible properly okay so sometimes  it may be visible or sometimes it is minimized
  249. 25:12it is not visible in that case it if it is not  properly captured the screenshot then you will
  250. 25:18get this exception screenshot exception so that  is the reason whenever you're trying to capture
  251. 25:23the screenshot and doing copy and everything you  put that in the tri block and in the catch block
  252. 25:28handle the screenshot exception if it is able to  capture the screenshot that's still fine if it is
  253. 25:33not able to capture then you will able to handle  the Exception by providing track catch blog this
  254. 25:40is related to screenshot exception now invalid  selector exception this is also very commonly uh
  255. 25:48we get this exception invalid selector exception  it's very simple suppose you have written some uh
  256. 25:55find element by. XO or css or ID what whatever  and you especially related to expath and CSS
  257. 26:02invalid selector exception is especially related  to expath and CSS and suppose you have created
  258. 26:08some incorrect xath or incorrect CSS then you  will get invalid selector exception incorrect
  259. 26:16in the sense what syntactically incorrect suppose  instead of using two slashes you have used only
  260. 26:23one single SL forward slash and instead of  keeping single code you suppose you forgot to
  261. 26:28put double quotations in the bracket so if expath  CSS syntax is correct in syntax is incorrect then
  262. 26:36you will get invalid selector exception so most  of the times we will check xath and CSS uh in
  263. 26:41selector Hub whether they're properly trying to  locate element or not then we will use them in
  264. 26:47our automation skript most of the time we don't  directly use in our automation skript so there
  265. 26:51are very less number of chances are there to get  this exception but sometimes by copy pasting if
  266. 26:57you miss something if you miss some syntax then  you will get invalid selector exception especially
  267. 27:01for expath and CSS okay now safe side what we can  do is we can put that locator in the tri block and
  268. 27:11if it is thrown invalid selector exception then  can handle with the catch block just providing
  269. 27:16message to the user that is invalid selector  exception if xath is syntactically incorrect
  270. 27:23or css is also syntactically incorrect then you  will get invalid selector exception now next one
  271. 27:33invalid session ID exception invalid session ID  exception so what is session ID means what is
  272. 27:42the session ID so whenever you trying to launch  or whenever trying to create a driver instance
  273. 27:50like whenever you say driver equal to web driver  driver equal to new Chrome driver you're creating
  274. 27:55the object for Chrome driver right so that time  the session will be created one session will be
  275. 28:01created Chrome browser session or edge browser  session or Firefox browser session will be created
  276. 28:07so when you will get invalid session ID exception  suppose when you're trying to use web driver after
  277. 28:13session has been terminated you are trying to use  web driver after session has been terminated for
  278. 28:20example let's say web driver driver equal to new  Chrome driver you created so that will actually
  279. 28:24create the session and immediately you you quit  it or close it after that you're trying to do
  280. 28:31some activity so before doing activity itself you  already quitting from the browser already quitting
  281. 28:37from the brow closing the browser so obviously  when I use close or quit command what will happen
  282. 28:43session will be closed so the session ID no  longer available so in that case you will get
  283. 28:49a invalid session exception if the session is not  available that is already session ID is closed by
  284. 28:55quit or close command but still you are trying to  interact with the page your element then you will
  285. 28:59get invalid s exception so once you created your  driver instance you should not close it till you
  286. 29:07complete your activities or till you completed  all the actions on the page okay so by mistake
  287. 29:13if you close the page and then you are trying  to do some activity means you will get invalid
  288. 29:17session exception so that is the reason you can  just try to put driver. get inside the tri triy
  289. 29:23block whenever you're launching the page put that  in the Dy block and in the cash block Cas invalid
  290. 29:29session exception and then you can provide message  to the user this is invalid session ID exception
  291. 29:39next one timeout exception and this is especially  related to uh explicit weight time out exception
  292. 29:47explicit weight so normally implicit weight  also we specify the time right but implicit
  293. 29:53weight is applicable for all the elements so  if the suppose I'm looking for some element
  294. 29:58and let's say I in implicit we I put 10 seconds  maximum and element is not available within 10
  295. 30:06seconds so obviously you will get an exception  related to Element no such element exception
  296. 30:11something like this but you won't get timeout  exception there but in case of explicit weight
  297. 30:18also we will specify the time right in explicit  weight but how we will use this explicit weight by
  298. 30:24putting proper condition let's say I written like  this expected conditions do visibility of element
  299. 30:30located some element I provided also I put some  conditional method suppose within this particular
  300. 30:37time this condition should be satisfied if this  condition is not satisfied within 10 seconds
  301. 30:43then time out exception will come it is based on  the condition and time but in implicit weight we
  302. 30:48don't put any condition so obviously that will  throw exception implicit weight will not throw
  303. 30:54time out exception but only explicit weight will  throw time out exception so if the condition is
  304. 31:00not satisfied within this time then you will get  a timeout exception which is related to explicit
  305. 31:08weight so safe side what we can do these weight  statements also we can put in the trage Block in
  306. 31:14case if there is an timeout exception we can  handle properly using catch block and we can
  307. 31:19exit the program properly without terminating it  so element not found within the time limit you can
  308. 31:24just provide proper message to the user and then  you can exit from the program so this is Timeout
  309. 31:29exception so timeout exception is basically  related to what explicit weight or fluent weight
  310. 31:36not related to uh implicit weight okay next one  insecure certification exception this is related
  311. 31:47to SSL certification what is SSL means SSL secure  socket layer so through when selum is unable to
  312. 31:57verify certificate of the yeah secure socket  layer so unable to verify the SSS certificate
  313. 32:04of the website with an insecure connection so  normally if I open any website which is not
  314. 32:10having SSL certificate or invalid certificate  so then what happens by default you will get an
  315. 32:16exception insecure certificate exception you will  get but to avoid that exception what we can do we
  316. 32:24configure that in the Chrome options right in the  Chrome options we can pass these parameters we can
  317. 32:30create a chrome options class and in option  there is a method called set accept insecure
  318. 32:34certificates make it as a true in that case  the exception we can avoid insecure certificate
  319. 32:40exception we can avoid but if you're not handling  this for example it's not handling this there is
  320. 32:46no SSL certificate valid then definitely you  will get an exception but if you still want to
  321. 32:53continue with that website with with By ignoring  CER SSL certificate then you can say options do
  322. 32:59set accept insecure certification make it is  true and pass the options object in the driver
  323. 33:06so that will solve the problem okay so this is  insecure certificate exception related to SSL next
  324. 33:14one invalid argument exception  invalid argument exceptions Okay so
  325. 33:28in implicit weight or explicit weight can we  pass negative time time in negative value no
  326. 33:34time cannot be a negative value right so when you  pass a negative value that is obviously invalid
  327. 33:40argument so duration of half seconds should accept  only integers but here I'm passing minus 10 even
  328. 33:47it can be implicit we or it can be explicit we  whatever basically it is invalid argument it is
  329. 33:52not accepting so that case that will throw invalid  argument exception so whenever you using implicit
  330. 33:59weight also all explicit weight keep them also in  TR cach Block in case any issue comes that will
  331. 34:05through exception invalid uh argument exception  you will get and you can provide message to the
  332. 34:10user so we cannot give the invalid values here  we don't give it because we know but sometimes
  333. 34:18if there is any Mistake by mistake if unknowingly  if you provide any negative value then you will
  334. 34:22get a invalid argument exception next one web  driver exceptions most of the times you'll
  335. 34:30get this whenever you start running your skit  immediately you will get this first of all it
  336. 34:35will not launch browser itself immediately you  will get web driver exception so when you will
  337. 34:40get this web driver exception most of the times  exception Throne when something goes wrong while
  338. 34:47interacting with the driver while interacting  with the driver or when you're creating the
  339. 34:53driver instance if something is go goes wrong  then you'll get a web driver exception so what
  340. 34:58could be the reasons maybe the browser versions  are not compatible okay suppose you using the old
  341. 35:06Chrome version or you are using latest Chrome  version then there is no compatibility right
  342. 35:12and similarly if you're using latest version of  selenium but browser is very old then again no
  343. 35:16compatibility browser is latest but we are using  very old version of selenium so then also there is
  344. 35:22no compatibility so in that case if there is any  conflict between your driver and your browser you
  345. 35:28will get a web driver exceptions so at the time  of creating web driver driver equal to new Chrome
  346. 35:34driver so you will that will not execute first  of all the driver creation itself will fail in
  347. 35:40that case you will get a web driver exception  so better to keep those statements in the TR
  348. 35:44catch block itself if there is any problem you can  safely exit from the program without interruption
  349. 35:50so web driver exception you can put in the catch  block you can provide General web driver exception
  350. 35:54is occurred and again you need to check all the  versions and properly aled or not then you can
  351. 36:00fix that so this is web driver exception if  web driver exception comes your script will
  352. 36:05not continue first of all even the browser itself  will not launch if you have web driver exception
  353. 36:11because at the time of creating the driver itself  you have some issue with that this is web driver
  354. 36:18exception next one session not found exception  session not found exception and this is also again
  355. 36:28same kind of a scenario previously we have seen  invalid session exception same thing related to
  356. 36:33this suppose you have quit from the browser  but still you are trying to do some activity
  357. 36:38see here I have quit from the browser already but  still I'm trying to use the same driver instance
  358. 36:43will it work no session has already ended by quit  command so this will not work so this will throw
  359. 36:49session not found exception session not found  exception so make sure to check if the session
  360. 36:55is still active before performing the operations  or handle the exceptions so whenever you do some
  361. 37:02activities you have to check the session is still  alive then only can do that okay so keep the whole
  362. 37:08code in TR the inside the TR catch block if it  is got failed session is not available or session
  363. 37:15not exception through then catch block you can  specify that exception and provide message to
  364. 37:19the user session is already closed or session is  not found something like that so this is another
  365. 37:26exception session not found exception these are  small exceptions but by mistake unknowingly we
  366. 37:32will do certain things so because of that we will  get these kind of exception but most of the times
  367. 37:36nobody will do right after repeting the browser  will you do any activity no right most of the
  368. 37:41times we don't do that but unknowingly sometimes  it will happen so in that case you'll get a
  369. 37:47session not found exception so better to keep  inside the tri block also then you can put proper
  370. 37:52message in the catch block so session not found  exception so when you will get this exception
  371. 38:00so when you do some activity after quitting the  browser after quitting the browser means session
  372. 38:06is already closed then you will get a session not  found exception next one I think this is the last
  373. 38:13exception now there is a small clue here guys  suppose you don't know the exception name but you
  374. 38:20still want to use TR catch or still you want to  handle the exception properly then what you can do
  375. 38:24you can put the entire code in the TR catch block  that ly and you can specify different type of
  376. 38:30elements or different type of exception one group  let's say no such element or St element reference
  377. 38:36exception or element not interactable exception so  like this you can put different type of exceptions
  378. 38:43and then you can put proper message to the user  so this is also the general way to handle the
  379. 38:50exception so better to keep all the statements  in proper Tri blocks and handle them by Pro
  380. 38:55providing proper exception option names through  catch block but some exceptions we can solve by
  381. 39:01using JavaScript executor or web driver weight but  certain exceptions we cannot solve because that is
  382. 39:07problem with the application not from the side not  from our side okay for example let's say there is
  383. 39:12a button which is disabled state by default it is  a disabled and if you're trying to perform some
  384. 39:17action how it is possible so the developer should  enable that button then our script will work so in
  385. 39:23that case we cannot solve we simply exit the code  without elmination but suppose element is there
  386. 39:29in the page but somehow it is hidden in that  case we can make it available make it visible
  387. 39:35then we can perform the action forcefully we can  do using JavaScript executor that will solve the
  388. 39:40problem so certain things will solve the problem  certain things may not solve the problem similarly
  389. 39:45element click intercepted exception so when you  will get element click intercepted exception the
  390. 39:51element is there but you are not able to click  on that element especially this will happen
  391. 39:55for checkboxes radio buttons links buttons so  element click intercepted exception when you'll
  392. 40:00get sometimes the elements are overlapping and  sometimes the page is minimizing or maximizing
  393. 40:06that resolution changes because of Click may not  work on the element properly so then you can do
  394. 40:12that forcefully using JavaScript executor and  if you're doing some activity using JavaScript
  395. 40:17executor what does it mean you're trying to do  the same activity forcefully through JavaScript
  396. 40:22executor we're trying to inject the JavaScript  executor statement directly inside the browser
  397. 40:27so not through web driver so through web driver  we are trying to execute the JavaScript statements
  398. 40:33directly on the browser but normally what happens  we are running the web driver methods or commands
  399. 40:39and through web driver method apis will be  interacted with the browser through JavaScript
  400. 40:43so in instead of interacting the browser through  web driver API we are directly interacting with
  401. 40:48the browser elements through JavaScript executor  so that's how we can solve certain problems but
  402. 40:54every problem is not solved okay for example let's  say I have written proper locator but the element
  403. 41:01itself is not visible on the page element not  visible exception will get ele no such element
  404. 41:07exception will get can we solve that problem  no until unless the developer plays the element
  405. 41:11on the page we cannot do that so simply we can  put that element in the TR cat block and proper
  406. 41:17message you can just write and exit from the  code without termination and spect can just exit
  407. 41:22from the code because the element itself is not  there in the page how we can perform the action
  408. 41:27so certain things we can solve through JavaScript  executor or web driver weights but certain things
  409. 41:32we cannot solve similarly stale element exception  stale element reference exception so whenever you
  410. 41:38refresh the page or reload the page you will get  stale element exception so developer no need to do
  411. 41:43anything with that we need to handle this because  we are refreshing the page multiple times there is
  412. 41:48a requirement to refresh the page so you need to  handle that using JavaScript executor or by using
  413. 41:54explicit weight statement okay so these are all  common exceptions most of the times we will get
  414. 42:0120 types of exceptions have listed out there are  n number of exceptions but difficult to remember
  415. 42:06each and every at least five to six exceptions if  you remember easily you'll able to address them
  416. 42:11in the interview point of view okay so that's all  for exception web driver exceptions concept okay
  417. 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.