Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

How do you identify an object using selenium?

Closed 1 Answers 34 Views
0 1
How do you identify an object using selenium?

Thank You Sir.
closed with the note: Got it, sir

1 Answer


There are 8 ways you can identify object using Selenium.

  • ID
  • NAME
  • CSS Selector
  • Link
  • Partial Link text
  • XPath

In Java,

  • ID: driver.findElement("element id"))
  • CLASS:driver.findElement(By.className("element class"))
  • NAME: driver.findElement("element name"))
  • TAGNAME: driver.findElement(By.tagName("element html tag name"))
  • CSS Selector: driver.findElement(By.cssSelector("css selector"))
  • Link: driver.findElement("link text"))
  • Partial Link text: driver.findElement(By.partialLinkText("partial link text"))
  • XPath: driver.findElement(By.xpath("xpath expression"))

In Python,

  • ID: find_element_by_id
  • CLASS: find_element_by_class_name
  • NAME: find_element_by_name
  • TAGNAME: find_element_by_tag_name
  • CSS Selector: find_element_by_css_selector
  • Link: find_element_by_link_text
  • Partial Link text: find_element_by_partial_link_text
  • XPath: find_element_by_xpath

Xpath can be of two types, absolute and relative. You an read more about it here: What is the difference between a single and double slash used in XPath?

Also, in case of you have multiple elements present with the same locator, you can use findElements to identify all elements on the page. It will return as List of WebElements in case of Java.

Hope my answer helped! Feel free to comment for further questions.

answered by (151 points)