0
How do you identify an object using selenium?

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

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

1 Answer

0

There are 8 ways you can identify object using Selenium.

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

In Java,

  • ID: driver.findElement(By.id("element id"))
  • CLASS:driver.findElement(By.className("element class"))
  • NAME: driver.findElement(By.name("element name"))
  • TAGNAME: driver.findElement(By.tagName("element html tag name"))
  • CSS Selector: driver.findElement(By.cssSelector("css selector"))
  • Link: driver.findElement(By.link("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 Nov 29, 2016 by stbadmin (4,970 points)
...