By tagName() method to locate the web element

Tag name is used to locate the web element such as button, link, hyperlink etc.,  For example, on linkedin.com login page, user will be able to see more than one tag name is exist for submitting button.

In the below code example, user can locate the web element using by tagname.


The code does collecting all the button's in the list array and will be printed in the console.


Code:
import java.util.List;
import java.util.concurrent.TimeUnit;  
import org.openqa.selenium.*;  
import org.openqa.selenium.firefox.FirefoxDriver;  

public class bytagname{
public static void main(String[] args){

//Launching firefox Browser
WebDriver driver = new FirefoxDriver();

//Launching linkedin.com
driver.get("http://www.linkedin.com");

//Getting all the button tagname and listing in to an array
List Lbuttonlist = driver.findElements(By.tagName("button"));

//printing the result into the console

System.out.println("Total count of the button on the linkedin Home page is : " +Lbuttonlist.size());
System.out.println(Lbuttonlist);

}
}
Output:
Total count of the button on the linkedin Home page is : 24
[[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button], 
[[FirefoxDriver: firefox on WINDOWS (76e48110-da90-4264-8df8-2ff845b138f8)] -> tag name: button]]
Socialize It and Share the post with your friends
SOCIALIZE IT →
FOLLOW US →
SHARE IT →