What will you learn in this lecture?
In the previous video, we learned how to use ClassName to identify an element of this Selenium webdriver elements identification course. In this video, we’ll have to learn how to use name property to do the same.
How to Use Name Property to Identify an Element
So the next property that we can use is the name property,
Again, not as good as IDE is always the best but if you must use it, just make sure that it’s unique. The hardest thing for Selenium webdriver is always finding that unique combination of elements to help you identify the appropriate element and not anything else. You want just enough properties to make the elements unique, but not too many so that you are just wasting time.
So let’s go back to our website and take a look this button uses the name property so we can use again Firebug. Hover over it and click on that and you guys can see that it has name called name example.
So I’m going to copy that property. I’m going to come over here. Leave all. Get rid of all this and again I want to do this for you guys on the fly with less explanation.
So see how I did that uncommon this Control K U and then common this control K C and now let’s go ahead and run it. And of course, I didn’t click do and if we’re successful, it’s going to click on this button and why won’t it click on any other button because I have specifically made this unique.
Right, look at all these buttons are exactly the same. They just have different content in the tags. So look at this one, and now let’s look at the third one and the first one is also different.
It just has an ID, so you guys can see the second one has a class. The one below doesn’t. They’re both types of needs. Their values are obviously different because I wanted to show you guys what each button does and then this one has a name property and this one does not so obviously they’re almost the same.
The text is also a little bit different.
I could have made them all exactly the same and just change one of the properties but either way, you can see how if we identified our element correctly it will only click on this button and not the other button, not the second button.
So let’s open up our Visual Studio and I’m actually just going to go ahead. Come here and do a run so that you guys can see everything in real time.
So you guys can see started running the test. Here’s the browser and actually it did not. It was too fast for you guys to be able to see the restaurant, right. But you can see that the tests passed no errors were thrown, therefore, the tests worked.
So that’s how we know that it works. I wish was a little bit slower but it’s okay.
I think you guys get the point that award otherwise, it would have thrown an exception like oops check it out it would throw no such element exception. You guys see that over here. No such element exception. No such element exists.
So that’s how you know that your element wasn’t found and then if you’re looking at the stack trace, you can actually figure out where that happened at line 33 over here so that’s finding the element broke which is exactly the problem because I made up this name and so there is no such object with this name and so it was not found.
[Tweet “Learn everything about elements identification with Selenium Webdriver.”]
In the next tutorial, we will cover how to use link text to identify an element in selenium.
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!.”
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
[Tweet “Learn how to correctly identify elements using #Selenium #Webdriver.”]