Passionate to Quality

How To Find Element In Selenium Webdriver


Selenium Webdriver is open source and very popular automation testing tool today. To find element via selenium webdriver is first requirement when you start automation testing using selenium webdriver.

Following are ways using which you can find web page element for automation :

  • By Id

This is very simple way to find webpage element. Each and every element in your webpage has unique id assigned. Using that Id you can find Element.

For Ex : driver.findElement(“your element id”));

  • By Classname

If you element contains classname then you can detect that element by classname also.

For Ex : driver.findElement(By.className(“classname”));

  • By Name

You can find element by name property also.

For Ex : driver.findElement(“Name of Element”));

  • By Xpath

Xpath is very helpful when your 2 element having same id or name or class name and you want to find both element uniquely.

For Ex : driver.findElement(By.xpath(“xpath of your element”));

  • By Cssselector

You can find element using selector also. It is actually Css path of your Element.

For Ex : driver.findElement(By.cssSelector(“your element selector”));

  • By Tagname

If you want to find all element from page having tag <a> , then you can use this method to find all elements. Tag can be <a> , <Input> etc.

For Ex : driver.findElement(By.tagName(“a”));

  • By Linktext

You can find element by linktext , It means text which is having some link.

For Ex : driver.findElement(By.linkText(“text which having link”));

So above are easy and helpful ways by which you can find specific element from webpage.

Email Us for any query


DISCLAIMER provides QA services world wide. We Specialized in Manual Testing, Automation Testing, Web Testing and Mobile App. Testing. We focus on providing top notch Quality assurance services.