Do you have questions ? We got the answers!

Ask a question:

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)

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 364 pointssumitkumarwatts

    0 questions 14 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...