Saturday, December 24, 2016

Lesson #9 - Selenium WebDriver - Finding element using the ID attribute (C#)

Overview

תמונה קשורה
The ID attribute is the most common and probably the most simplified way to locate web elements, in real automation projects, the developers will assign a unique ID for each web object that we can use to identify the element without the need to use more advanced and complex locators. 



In addition:
  • Elements should be set as static and not dynamic.
  • The ID uniqueness must be enforced by the developer.
  • Many Web Elements are not including such parameter. 

Code Example








Let's use the ID attribute to locate the "Name" field in the contact form

HTML
<input type="text" value="" size="30" name="name" id="ContactForm1_contact-form-name" class="contact-form-name">

C# Code 

[TestMethod]
public void FindElementById()
{
IWebElement WebElement;
IWebDriver Firefox = new FirefoxDriver();
Firefox.Navigate().GoToUrl("http://www.machtested.com/");
WebElement = Firefox.FindElement(By.Id("ContactForm1_contact-form-name"));
}
}

Friday, December 23, 2016

Lesson #8 - Type of Locators available in the Selenium WebDriver API

Overview

Selenium WebDriver API, provides two functions that we can use for locating Web Elements, each function is used for a different purpose, as follows:

The FindElement () function is used when we need to work with a single web element, when executing this function; it will return a single object (Based on the search criteria) or throws up an exception.

The FindElements () function is used to retrieve more than a single element (Collection of elements).

תוצאת תמונה עבור ‪locators in selenium webdriver‬‏

Type of Locators


Locator Name
Code syntax (C# )
Description
ID
driver.FindElement(By.Id("Element ID"));
Locates an element using his ID
Name
driver.FindElement(By.Name("Element Name"));
Locates an element using his Name
Link text
driver.FindElement(By.LinkText ("Element link text"));
Locates an element using his Link Text
Class Name
driver.FindElement(By.ClassName("Element class name "));
Locates an element using his class name
Tag Name
driver.FindElement(By.TagName("Element Tag name"));
Locates an element using his tag name
CSS
driver.FindElement (By.CssSelector("Element CssSelector"));
Locates an element using CSS
XPath
driver.FindElement(By.XPath("Element XPath"));
Locates an element using XPath query
Partial Link text
driver.FindElement(By.PartialLinkText("Element PartialLinkText"));
Locates an element using a partial link text

Wednesday, December 21, 2016

Lesson #6 - How to Install Firebug Add-on in Mozilla Firefox?

Overview

Firebug is a basic add-on that available in Mozilla Firefox, it is used to query web elements and to gain their unique identifiers.


How to install?

The installation process is really simple, nothing that should challenge you, just follow this basic steps.

Step 1: open the Mozilla Firefox browser.

Step 2: Navigate to the Mozilla Firefox Add-ons center, this link will do the work:


Step 3: Under the “Firebug” Grid, Select the “+ ADD to Firefox”



Step 4: in the security “pop-up”, select “Allow”



Step 5: Firefox starts the download process, after download completed, you will see the “Software Installation” window, Select “install”


 

Step 6: Once the installation process is finished, you will see a notification indicates that the installation process is finished and that the  “Firebug” add-on is now available and ready for use.

My Presentations