What will you learn in this lecture?

In the previous video, we learned the webdriver commands in this Selenium webdriver elements identification course. In this video, we’ll have to learn how to use className to identify an element.

How to Use className to Identify an Element

So let’s talk about a className.

ClassName is obviously the name of the attribute and it’s okay, not as good as an ID and use it only if you must. Sometimes it may be unique, sometimes it’s not that’s for you to figure out whether it gives you a unique identifier.

So for example, if we come back to our automation testing practice page and we hover over this button that says “click this button using class,” this one has a class, so you guys can see here that its attribute is name class and then its values button class example.

So if we take this value and we come over to our Selenium IDE and rather than doing this, I’m going to do it for you guys from scratch. We’ll do the standard driver dot. First, let me set it equal to a variable of our equals. Actually, we don’t even need to because I created a private element up here. So we have to do is element equals. We don’t have to declare it driver dot find element by how class name and supply the value and then scroll over here, put the semicolon. We come back here uncommon that so that it navigates back and let me comment this so that it doesn’t do that control K C is quickly to comment you can also just highlight go to edit advanced and comment selection okay that’s in Visual Studio 2015.

I think in the other ones it’s a little bit different because I think in 2013 was like control C U or something I forget I it’s knowing how they always change it but that’s what it is for me now but you guys can do it through the advanced edit.

Anyway, so now we have that set so if I run this and actually that’s do a debug when I do debug pulls up our unit test runner then it pulls out the browser. So now we’re here if we step over this we’re going to have our elements sword you guys can see we can look at it easily right here that’s why I like that two line technique. You can see its size tag name import taxes and have any text whatever else.

And now if we hit, oops and of course I forgot to do the click, so one nice thing about visual studio is it allows you sometimes to edit on the fly in debugging mode. So if I do element dot click put that in there so now it’s going to click and you see right now this arrow is pointing to this line. I can actually move it up one like that so now it’s going to do this line instead.

So I’m going to step over and now it’s click and check it out button success because it was button success it means it clicked on the right button and now we can just go ahead and do an F5 to run through everything and the reason I did that F5 is because I added a test cleanup method here at the end of the test so that it does a driver dot close and the driver dot quit.

And let me pin this over here so that it stops bothering me excellent and so the driver dot close and the driver dot quit. You can see this one closes the current window quitting the browser and then the “quit” quit this driver closing every associated window.

Excellent. So I’m going to save that.

Next Tutorial

In the next tutorial, we will learn how to use name property to identify an element.

What will you learn in this course?

Are you struggling with working with HTML using Selenium WebDriver? Do you know how to easily identify an element using Selenium WebDrriver? Do you know how to manipulate that web element? Do you know how to perform a drag n’ drop on an element? If not, then these are just a few of the questions that will be answered in this course.

This course is a complete guide on working with web elements in Selenium WebDriver! Once you are finished with this course, you will know how to work with any web elements, any time, on any web application.

“Relevant content that I will be able to apply to my automation tests *immediately*, a VERY effective presentation approach (evolving the same example and comparing/contrasting), and an excellent teacher / presenter. Thank you so much for your time and sharing your knowledge Nikolay!.” 

-Krissy

In this course from Ultimate QA, you will learn:

  • Basics of HTML
  • All the different locator strategies for Selenium WebDriver
  • How to identify web elements using Selenium WebDriver
  • Master XPath
  • Navigation with Selenium WebDriver
  • Web element manipulation
  • Web element interrogation
  • Mouse and keyboard actions with Selenium WebDriver
  • Performing actions such as drag n’ drop, drawing, hovering
  • Implicit and Explicit waits
  • How to properly handle element identification so that your tests are not flaky
  • Expected Conditions in Selenium WebDriver

Take This Entire Course for Free

Nikolay Advolodkin is a self-driven SDET on a lifelong mission to create profound change in the IT world and ultimately leave a legacy for his loved ones, community, and the world at large. Today, he serves as the CEO and Test Automation Instructor at UltimateQA.com and contributes informative articles to leading test automaton websites like SimpleProgrammer.com and TechBeacon.com

Pin It on Pinterest

Shares
Share This