How To Handle Element Not Clickable At Point Exception - Selenium WebDriver Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all welcome back to the next one in this one we're gonna look at element not clickable exception it is not a very frequent exception that we see on any web application but it is one of the most tricky to solve and that makes it one of the very popular interview question so let me just quickly bring up Eclipse and let me quickly try to show you a code and then see the exception then we will talk about it because it'll make more sense to you when you actually read this exception because it's quite detailed so here I have just the code for bringing up the chrome driver then bringing up this website free CRM and finding the element username sending some keys then finding a login button I'm not bothering about finding the password just clicking on the login button that's it so these are just the expats and the name and that's about it so let's just right click this run as unit test for now it's gonna bring up the application and here you're gonna see it typed testing but it didn't click the login button because we don't see any error or we don't even see this thing going away so let's see if I click login it reloads it and everything just goes are we right so what happened on the back end we can see here you go here is an exception if I maximize it I can see it says something unknown error element input' type submit' value login which means the one that we were trying to find so if you take a look at it we found the element for the login button using input value login right that's the XPath that we created and it says this element is not clickable at point some 1108 and one one seven and then it tells us other element would receive or click and it tells you the element also that will receive a click it says there's a div element with ID preloader and this is gonna receive the click so this is where right we kind of found the element and this guy worked it typed the testing text inside the username field but it didn't click the login and why is it happening so if you notice and I'm gonna actually just open the website again to show you what's happening just pay close attention that if I open this website there is a rotating icon which is a loader kind of thing which is always there and it's moving on and pay attention on the top right here the spinning icon here on the browser goes away early but the rotating icon here takes some time a couple of fraction of seconds to actually go away which means when the browser loading complete it means from the browser perspective website is loaded but here some Ajax call is going on the website is not completely loaded the element might be present in the Dom which it is because selenium is actually able to find the element right if we call it as element a the login button selenium is able to find the element but it's not able to click it why because it thinks that some other element will receive a click and that some other element is actually the preloader if you see let me just do it again this loading icon that shows up for a fraction of second selenium tries to click it and it thinks that this element is going to receive the click now how do we resolve this this is the big question right so the first thing that comes to our mind is that we can actually try to use explicit weight instead of just using this finding element we can try to use explicit weight and then find the element weight for the element to become visible and then click it so let's go ahead and that out so for that we're gonna do web driver weight weight equals to new web driver weight and this guy is gonna take tribal and maybe three seconds good enough and then we're gonna say web element login button right here and then wait dot until and then inside it we're gonna say expected conditions dot we can try to use visibility of the element so visibility of element located and then this guy is gonna take the XPath right so here I can use the same expat this thing so by this and that should be it put one more of this and this so looks good we actually utilized web driver weight which is explicit bait and trying to wait till the element is actually visible and then let's try to click it not click and now let me just again run it and then see what is the output so this time again it typed testing in the username field but it still failed and if we go back we're gonna see the same exception right we are seeing the same exception so basically using the expected condition this guy didn't help us what's happening there selenium webdriver is still thinking that the other element will receive the click so maybe it's visible to selenium webdriver but still another element is overlapping this guy right so what is the actual reason another element is overlapping this element and selenium webdriver is still thinking that I'm gonna click the other element so what we can do in this scenario is we can act silly wait till the other element goes away and then we can try to find this element and then click it instead of using this again let's comment it out we do have the web driver wait here what we're gonna do here is we're gonna say boolean invisible this is just a variable I'm declaring and I'm gonna explain why I'm gonna say wait dot until an expected condition dot I'm gonna wait for invisibility of element located and how do I find the element which is overlapping the actual element right so if we actually again look at the error message it tells us which element is overlapping the required one so it tells us that the the culprit the element which is creating an issue is a div element with ID preloader so we can actually just try to find this one we don't really have to look at the Dom because that spinning icon goes away pretty quick and it's very difficult to find that out if it had inspected so what we can do here is we can say by a dot ID and then inside it we can say pre loader and this is the guy we can try so this invisibility of element located this guy returns a boolean you can see here that's why we are capturing it inside a boolean variable and then what we can do here is if this invisible this thing is true which means the above condition is successful then what we can do here is we can simply try to find the element this guy and then click it so let me just copy this code here put it here and maybe let's get rid of it from this place we don't need it there and uncomment it and now try this code so right-click this one JUnit test it's gonna bring up the Chrome and boom if you see it waited for the rotating icon to spin and go away and then it clicked the login button because now we don't see the text here because clicking the login button reloaded the page in the text is gone away and we can go back and verify that there's no error the test is successful indeed and we were able to get rid of the exception that's one of the trickiest one we really have to understand the concepts instead of guessing what we need to do and wandering around oh my god what's happening but if we understand the concept if we understand the DOM and what may be happening and all those kind of things it's really easy to figure it out this another way we can actually fight with this exception I can just comment this guy out and what we can do here is we can use the JavaScript executor so I'm gonna say JavaScript executor Jas equals to the same guy casting and try but let me make some space here and then what we need to do here is we need to just use the JavaScript executes a start execute script and then write a small JavaScript arguments 0 dot click arguments arguments 0 dot click and we're gonna pass the element here so our element is this guy we need to find it so we can put this statement here and selenium webdriver will find it because the exception is coming on clicking the element not on finding it so we are able to find the element just we were not able to click it so we will pass the element here to the JavaScript and it's gonna actually click the element our way and it's not gonna wait for any element to disappear or appear it is just the hard way it's gonna go to the browser and click it it's JavaScript so let's go ahead and try this out run this code and see if this works so the above code is already commented and I'm gonna run it and let's see and there you can see that that it actually typed it quickly and then it clicked the login button again and everything is working perfectly fine no issues here right so this is also one of the way but in reality I would suggest you to use it as the second option or the first one the first one is this even though it's a little bigger or a little lengthy but still it's the best option because it is the right way it is actually waiting for the other element to go away and then clicking it so which make sure that your further flow will also work perfectly fine we don't want to use JavaScript unnecessarily that's about it if anyone talks about why element not clickable exception shows up you should be able to explain the exception and how we overcome it thanks a lot for watching this comment below if you have any questions please like and share this video with your friends and do not forget to subscribe us click the subscribe button to get more awesome videos like this and I'll see you in the next one
Info
Channel: Let's Kode It
Views: 20,095
Rating: undefined out of 5
Keywords: how to handle elementnotclickableexception in selenium java, how to handle elementnotclickableexception in selenium webdriver, how to handle element not clickable exception in selenium java, how to handle element not clickable exception in selenium webdriver, element not clickable exception in selenium java, element not clickable exception in selenium webdriver, elementnotclickableexception selenium webdriver, elementnotclickableexception in selenium java
Id: iaI1vcEAWlM
Channel Id: undefined
Length: 12min 36sec (756 seconds)
Published: Fri Jul 27 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.