What are the Browser Elements in Selenium ?

Comments · 220 Views

Testing these elements basically means you need to verify that they're functioning properly and are responding in the manner we would like it to.

Elements are all the various elements which are found in web pages. The most popular elements we can see when browsing include:

  • Text boxes
  • CTA Buttons
  • Images
  • Hyperlinks
  • Radio buttons/Checkboxes
  • Text area/Error messages
  • Drop down box/List Box Combo box
  • Table/ HTML TableHTML Table Table
  • Frame

Testing these elements basically means you need to verify that they're functioning properly and are responding in the manner we would like it to. For instance, if you test text boxes, what should you do to test it?

  1. We are not able to send numbers or text numbers in the message box
  2. Can we access text that has been sent to the text box etc.

If we're trying to test an image, we may need to:

  1. Download the image
  2. Upload the image
  3. Click here to open the image link
  4. Find the image's title, etc.

Similar to operations, they can be carried out on any of the elements previously mentioned. Once the elements are placed within the web page can we begin to perform operations and test the results, right? The next subject I'll cover on this Selenium tutorial blog is the use of element locators.

Searching for Browser Elements On the Web Page

Every element of any web page will be able to display properties (properties). Some elements may have multiple attributes and the majority of attributes are distinct for various elements. Consider, for instance, an element on a webpage that has two components that include an image and the text box. Both of these elements are equipped with an attribute called 'Name' and an attribute called 'ID. These attribute values must be distinct in each of the elements. That is that two elements can't have the identical attribute value. The elements can share the same attribute value for the 'Class Name'.

In the case we have looked at above, the image and the text box cannot have the same ID value or the same name value. There are however some characteristics that could be common to all elements on a page. I'll tell you what are those attributes lateron, but first, I will list the 8 attributes with which we can find elements. These attributes are ID Name, Name, Class Name Tag Name Link Text, Partially Link Text, CSS , and XPath.

Because the elements are identified with these attributes and attributes, we call them 'locators''. They are

  • By.id
  • Syntax: driver.findElement(By.id("xxx"));
  • By.name
  • Syntax: driver.findElement(By.name("xxx"));
  • By.className
  • Syntax: driver.findElement(By.className("xxx"));
  • By.tagName
  • Syntax: driver.findElement(By.tagName("xxx"));
  • By.linkText
  • Syntax: driver.findElement(By.linkText("xxx"));
  • By.partialLinkText
  • Syntax: driver.findElement(By.partialLinkText("xxx"));
  • By.css
  • Syntax: driver.findElement(By.css("xxx"));
  • By.xpath
  • Syntax: driver.findElement(By.xpath("xxx"));

When you examine the syntax below you'll have noticed the term locators is used to describe inside methods. Therefore, before you go any further, it is essential to be aware of the other methods that are available, such as browser commands, and functions that you can use to execute operations on elements. If you'd like to understand Selenium and make a name for yourself in the field of testing, take a look at our live, interactive Selenium Training in Hyderabad here. It is a great resource, and is supported 24 hours a day to help you through your learning experience.

Comments