We are going to find an element on the page by using find ElementByClassName() method that is on each of the Browser Driver classes.find Element calls will return a WebElement object that we can do actions on.
Follow these steps to see it work:
Open your Java IDE. Intellij or Eclipse are the most used that you could use.
We are going to use the command:
Run the test from the IDE. It will look like the following screenshot:
What just happened?
We have just seen how we can find an element by using the findElementsByClassName helper method. After running the test, we saw that it passed. Unlike its singular version, it will not throw a NoSuchElementException if the element is not found. It will return a list that has a size of zero. If you want to use CSS selectors, you can use find Element By Css Selector or find Elements By Css Selector. In the next section, we will have a look at XPaths.
Finding an element on the page by their XPath
XPath is one of the most useful approaches to finding elements on the page. It has a bit of a tainted past due to the speed that it takes to look up elements on the page. We learnt a number of different techniques using XPath earlier in the book.
This method is a helper method that sets an argument for a more generic findElement call. We will now see how we can use it in action. The method's signature looks like the following:findElementByXpath(String using);
The using variable takes the ID of the element that you wish to look for. It will return a WebElement object that we can then work with.
Selenium Related Interview Questions
|SILK TEST Interview Questions||QTP Interview Questions|
|JMeter Interview Questions||Automation Testing Interview Questions|
|Software testing Interview Questions||JUnit Interview Questions|
|TestNG Interview Questions||SAP Testing Interview Questions|
|Selenium WebDriver Interview Questions||Selenium IDE Interview Questions|
|QUnit Testing Interview Questions||Performance Testing Interview Questions|
|Hadoop Testing Interview Questions|
Getting Started With Selenium Ide
Overview Of Selenium Webdriver
Working With Webdriver
Getting Started With Selenium Grid
Advanced User Interactions
Working With Html5
Migrating From Remote Control To Webdriver
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.