How to find an element by Class Name in Selenium?

devquora
devquora

Posted On: Feb 22, 2018

 

There are distinct ways to easily locate an element in Selenium. Some of the common ways of achieving this are through Tag name, id, class name, etc. A Class Name locator offers the web element which matches or suits the specified values in the attribute name "class". The first element that has the class attribute name that matches is returned. On the other hand, if there is no Web element that has the class attribute name that matches, a NoSuchElementException is raised.

Take a look at the code below to understand better

<html>
<body>
  <p class="content">website content moves here.
</body>
</html>

You can easily locate the "p" element by:

Web content = driver.find_element_by_class_name('content')

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Selenium Interview questions

    What Evaluation can Selenium Do?

    Selenium Could be Utilized for the purposeful, Regression, load testing of the Internet-based program. The Automation To..

    Selenium Interview questions

    Just how much does Selenium License cost per Customer Device?

    Selenium is open-source software, released under the Apache 2.0 license and can be downloaded and used without charge...

    Selenium Interview questions

    Where to obtain Selenium ?

    Selenium Can be Downloaded and Installed for free-form Seleniumhq.org..