Never should have I ever -Season Selenium, Java — Part 1
Yes, this would be many developer’s mind voice once they figured out that teeny tiny missed or misplaced symbols and punctuations (; , /) which caused a complete upside down output than the supposed one and made them to pull their hair for hours. So here we come with some basic silly mistakes many(if not every) developers can relate with their budding stage.
Disclaimer: Thanks to the developers who are helping to resolve each and every issues posted in the Numpy Ninja’s Brain-Pickers channel with out any judgement.
Let’s settle some illegal issues first…
1. IllegalStateException :
As the name suggests, it means the java environment or java application is in an illegal or inappropriate state for the requested operation. Though this exception comes with various scenarios (while handling collection frameworks like LinkedList, Queue etc.. which will be covered in future posts) most commonly this is thrown while working with any browser when the driver path in the “driver.setProperty” is incorrect.
Solution: Make sure the the driver.setProperty has the complete driver path of the executable(.exe) file not the zipped one.
In the below image the driver path is missing the complete path of the edgedriver’s executable file (C:\\SeleniumDrivers\\EdgeDriver\\msedgedriver.exe) hence we got the exception.
2. Static or Non-static :
“Can not make a static reference to a non static field/method” does it look familiar? The immediate response to this error message is obviously either make the field static or make the method non static but only a few know the why part.
All the variables and methods without the “static” key word are associated with the instance of the class, so each object we created for a class can have it’s own copy of this fields and methods , whereas a static field is unique and not making copies for every instances created. That’s is why in the below examples the right side string variable can have it’s own assigned value along with every new instance being created but the left side static variable can hold only the latest assigned value
The Non-static fields/methods must belong to the instances but the static fields/methods are not and can be accessed with the class name itself so the compiler throws the error message.
3. String.replace()/String.concat() not working :
Why the string variable is still having/showing the old value even after it has been changed with the .replace() method? If someone got this question then he/she is yet to know the immutable property of a JAVA String.
String object in java is immutable and it can not be changed so after any manipulation over a string object, that manipulated one should be assigned to a variable. Though our replace method is working as expected it can not change the value of the original string variable. JVM will only create a new string object in the memory as shown below.
To make it work, all we have to do is assign the result of the “Replace()” method into a string variable as shown below.
Let’s see some more pretty blunders in our next blog!!!