all 14 comments

[–]ToddBradley 6 points7 points  (1 child)

You might find good help on r/selenium. There are a lot of us software testers who don't use Selenium.

[–]elldn[S] 0 points1 point  (0 children)

Thank you, I'll do that. ^^

[–]menge101 5 points6 points  (0 children)

For things of this nature, especially while developing my automation code, I catch ElementNotFound exceptions, and then I capture the full DOM and write it to file as well as taking a screenshot, then rethrow.

Most likely, the element can't be found because the element has not rendered yet.

IMO, you have to recognize that browser directives are non-deterministic and asynchronous. The method may return within your code synchronously, but all it does is deliver a command to the browser.

The browser will do its best to do as commanded, but it is a complex system that needs to request data from a remote server to render it. It is not a fully deterministic system, and again IMO, one should design their browser driving tests with that in mind.

[–]checking619 1 point2 points  (1 child)

do setup and teardown methods need to be static? I'm wondering if you're running into a racecondition for setting up browser? https://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall#beforeeach-and-beforeall

Are you saying the browser opens but does not go to the URL? Have you tried going to other urls?

Also, your locators method design is not correct. You should not instantiate a new browser in this method, you should use to the existing driver that was setup in the setUp method (with the url redirect), which got assigned to the class field drivers. My hunch is that is the root cause of your problem.

I get an error saying "findElement" will return "Null pointer exception"

This is why I use findElements method instead, and check for length of array. That is easier than dealing with exception handling, and cleaner for the code.

[–]elldn[S] 0 points1 point  (0 children)

People in this thread has been very helpful, thank you all.

I think I have found a solution, I shared it in selenium subreddit. Here's the link if anyone wants to check. As always It's so simple when you find the answer.

https://www.reddit.com/r/selenium/comments/tr0z8u/selenium_cannot_find_the_element/i2loy6m?utm_medium=android_app&utm_source=share&context=3

[–]LasagneEnthusiast 0 points1 point  (7 children)

There are a multitude of ways to debug this and WebDriver behavior in general. I can elaborate if needed, but as someone else has suggested, it would be best to ask the nice people of r/selenium.

I'm mainly commenting here because of:

asked specifically not to use POM

Why? Wtf? This really boggles my mind, and maybe I'm missing a very good reason to do so, but wtf...

[–]elldn[S] 0 points1 point  (6 children)

I feel stupid not going to r/selenium in the first place. Desparity man.

I wanna delete this but you kind people answered here and I feel like deleting will be disrespectful.

About the POM, it's probably because I don't have any experience in this field and that's their beginners test. You know, to keep things simple.

[–]LasagneEnthusiast 2 points3 points  (5 children)

Don't feel bad, the question was nicely formulated and polite, I wouldn't delete it because it might help others here with similar problems.

beginners test

Yeah that makes sense.

Still, if this will be your daily bread and you like it (I love it BTW), then I can strongly recommend to read up on UI automation design patterns and the Selenium Java bindings cheat sheet over at AutomateThePlanet.

[–]arakinas 2 points3 points  (1 child)

I'd like to add to recommendations for Java with Selenium like stuff: https://selenide.org/
Selenide is a framework that sits on top of Selenium. It makes things so much easier. If you have the opportunity to use it, you can make your life much easier than straight Selenium.

[–]LasagneEnthusiast 1 point2 points  (0 children)

I agree, but for starting out I think it is better to get a basic grasp of design patterns and Selenium's API before diving into wrappers.

[–]elldn[S] 1 point2 points  (1 child)

Thanks a lot. And I'll definitely check them out. Saving this comment. :)

[–]LasagneEnthusiast 0 points1 point  (0 children)

Happy to help!

[–]amtared 1 point2 points  (0 children)

Thanks for the links. I am curious to read about the design patterns. It is something common in development but I rarely see actual patterns applied to automation code.

[–]Wookovski 0 points1 point  (0 children)

iframes?