Finding locators in selenium

Before performing any operation on any web element or any web component we need to tell the web driver where exactly that element resides on the web page. We can see the web element with our eyes but webdriver can’t. We need to tell it, that go to this particular location and perform this particular operation. To do so we make use of XPath. XPath is the XML path of a web element in the DOM. When you visit a website in google chrome and right click on the web page and select “view source”, you’ll see an HTML page with huge chunks of HTML, CSS, javascript code. You’ll find that the web page is developed with huge chunks of HTML tags

Some common HTML tags are:

div=division
span=span
p=paragraph
a=anchor tag
tr=table row
td=table data
ul=unordered list
li=list item
ol=ordered list
h=heading
label
input
and so on.

These elements also have some attribute and their corresponding attribute values.

For e.g. a div tag also has a ‘class’ attribute, or ‘id’ attribute, etc. An anchor tag ‘a’ must have an ‘href’ attribute. These attributes must have some values like class name, or id name.

So we can make use of these elements to find the xpath of our web component. You can find xpath without using any additional addon like firebug or firepath. Open the website in google chrome and right click on the element for which you want to find the xpath and click inspect element.
Now on the inspect element window press ctrl+s.

The basic format of xpath is

//tag[@attribute name="attribute value"]

Suppose there is a division in html whose class attribute value is “abcd”, so we’ll write like this: //div[@class="abcd"]
It means, find a division tag in the html whose class attribute value is “abcd”.

If we write like this //*[@class="abcd"] i.e. putting an asterisk in place of tag, this means, find any tag in the html whose class attribute value is “abcd”.
If we write with a dot operator like .//*[@class="abcd"] here the dot represents the child node. It means the processing starts from the current node. To be more precise find any tag in the html whose class attribute value is “abcd” and start processing from current node. If we do not use dot and simply write //*[@class="abcd"] then it will search class with value “abcd” in the entire document.
If you further want to go inside a parent tag, then you can use a single slash in the middle of the xpath //div[@class="abcd"]/ul/li/a this means under the parent division whose class value is “abcd” find an achor tag which is under ul and li tags. All these xpaths represents either an element or a list of elements on the web page.

XPATH AXES

Axes are the methods used to find dynamic elements. There are instances when you’ll find that the attribute of an html tag gets changed. Due to this your previously written xpath won’t work if the attribute value of any of the tag gets changed. To overcome this, xpath axes have been introduced. These are nothing but the functions which can be used inside our xpath to fetch the correct location even if the attribute is dynamic. The first such function is

1. contains().

suppose there is an attribute value “btn123″, and the numeric figure keeps changing, the numeric part is not constant it keeps changing. so you can write .//*[contains(@name, 'btn')] this means find any tag starting from the current node whose name contains “btn”. OR and AND: You can use ‘or’ or ‘and’ inside your xpath. For e.g. //*[@type='submit' or @name='abcd'], this means select any tag whose type is submit or name is “abcd”. //*[@type='submit' and @name='abcd'], this means select any tag whose type is submit and name is “abcd”. The satisfaction of both conditions is necessary.

2. starts-with()

//label[starts-with(@id,'abcd')]
It means find a label whose id starts with “abcd”.

3. text()

.//td[text()='abcd']

4. following:

Find all elements in the DOM starting after a particular node For. e.g.
//*[@class='post-content']//following::a This means find all the anchor tags after ‘post-content’ class.

You can see, it is giving 18 anchor tags after ‘post-content’ class.

But what if you want a particular tag? For this you can specify the index as below.

5. ancestor:

Find all elements in the DOM starting before a particular node For. e.g.
//*[@class='logoCotainer']//ancestor::div
This means find all the div before ‘logoCotainer’ class.

6. descendant

All elements after current node
//*[@class='uppermenubar']//descendant::div
This means find all div after ‘uppermenubar’ class.

7. preceding

//*[@class='navigation']//preceding::div
This means find all div before class “navigation”

8. child

//*[@class='uppermenubar']//child::div
This means find all child divisions (div) of class ‘uppermenubar’

9. parent

//*[@class='navigation']//parent::div
This means find parent div of ‘navigation’ class

Now that xpaths are being found, you can now use them in your selenium script as below
driver.findElement(By.xpath(“//*[@class='navigation']//parent::div”));
Here By.xpath(“//*[@class='navigation']//parent::div”) will return a By class object. So ultimately we are passing a By class object in findElement method.

SUMMARY

In this lecture, we’ve learned that before performing any operation on the web elements, first, we need to find the exact location or path of that web element and instruct the web driver to go to this path and perform a particular operation. Unless we find the location or path of the web elements how can we instruct our web driver to perform a particular operation on that particular element? For e.g you want to click a button on the web page, or you need to input some text in the text field. First, you need to find where exactly that element is present on the web page. To do so, we can find the tags, attributes, values of those web elements from the page view source and write our xpath

Understand Your Expenses With Home Loan Calculations

Most expenses for a home loan seem small as compared to the principal amount, due to which people fail to take them into account and include them in the principal amount. Thus, it should come as no surprise when the final home loan calculations bring about EMIs that are shockingly huge to pay. It makes sense, thus, to include these minor expenses in your principal amount while calculating your EMIs with the home loan EMI calculators in India .

Processing fees:

It is a tiny percent of your principal amount and can even be waived off in certain cases. In most banks, it can be anywhere up to 1%. However, the final processing fee will be charged along with the requisite service tax.

Stamp duty:

This amount was earlier included in the principal loan; however, from mid-2012, this amount must be paid in its entirety separately. So, calculate the stamp duty and set aside sufficient funds for it like you would save up for the down payment. Since it costs up to 8% to 10% of the principal amount, you must include it in your home loan calculations carefully. As, you can’t pay it via EMIs, exclude it from the amount you enter in the home loan EMI calculators.

HLPP:

A home loan protection plan is a term insurance product for homes. You can pay it all at the start or you can pay it in monthly instalments. This choice mostly depends upon available funds after the down payment and stamp duty cost. If you plan to pay it on a monthly basis, you must include it accordingly in your EMI calculations.

Interest rate fluctuations:

These are really challenging to anticipate. Most people fail to include them in the home loan calculators in India . But, for floating and fixed interest rates, these fluctuations are very common. So it would be smart to make a few rough calculations to observe their impact on your EMIs. You should be in a position to pay off the EMIs in spite of the variations as they would occur eventually. Therefore, don’t plan your EMIs in such a way that there is no money left for these additional expenses.

It is imperative to foresee all these factors and understand their impact on your total expenses. A smart strategy would be to keep sufficient room in your monthly cash flow for these additional expenses. So, plan smart and choose well for your dream home.

The Enormous Health Benefits of Eucalyptus Essential Oil

There are numerous health benefits to be derived from eucalyptus essential oil. Unlike all other sources of essential oil, the primary source of this oil is very unique. It is derived from the dry leaves of eucalyptus tree leaves. It is one of the most beneficial essential oils globally that can treat various types of ailments.

Aside from being an agent in fighting various ailments, Eucalyptus can also boost hair moisture and keep your hair shining at all times. Other usages of the multidimensional oil also include cooking and skin treatment.

With further scientific researches on eucalyptus essential oil, it is evident that what is known today is only a meager of what can be derived from its usage.

Usage of eucalyptus essential oil?

It has been established that eucalyptus essential oil is used for medicinal and non-medicinal purposes. The following are some of the ailments that can be treated, managed, soothe, and improved with the aid of this essential oil when used independently or mixed with other contents.

Coughs

Eucalyptus is highly effective in treating coughs and flu. As an antiviral agent, it helps in losing a tight cough and clearing phlegm following a cold.

Upset stomach

An upset stomach causes a lot of pain and ruins an already planned schedule. Eucalyptus contains pain-killing contents, which makes it ideal in handling any case of an upset stomach and managing pain that may arise due to an upset stomach.

Infections

Infections can be of any kind. To use Eucalyptus, you can either ingest or apply directly to the skill in its complete form. However, it is best to ensure the Eucalyptus has appropriately diluted until it is safe for usage.

Burns treatment

Eucalyptus essential oil has a clean and cooling effect that enables it to soothe pain caused by burns and helps the skin recover fast from the impact of the burn.

Acne

Eucalyptus is also used in treating acne and skin oil due to its natural astringent contents.

Respiratory and tract infections treatment

Eucalyptus leaves oil also contains contents that can alleviate asthma, pulmonary, tuberculosis, and whooping cough. It can also be used as a firewall to prevent sinus health.

How to Use Eucalyptus Essential Oil?

Incense/Candle
Diffusing essential oil in classrooms, offices, and homes helps improve a straightforward thought process, calm the nerve and reduce anxiety. It also helps in enhancing the brain connection.

Bathing
You can use Eucalyptus directly with warm bathing water after it has been appropriately diluted. Eucalyptus essential oil can be mixed with pure oil using almond oil as a compliment. For bathing, add a minimum of 10 drops and a max of 14 drops to your warm bathing water before usage.

Massage
Eucalyptus can also be used as massage oil. It is highly effective in calming the nerves, treating muscle soreness, relieving stress, and aiding blood circulation to the brain.

Side effects of Eucalyptus:

Before taking Eucalyptus orally or applying it to the skin, you must ensure the oil has been appropriately diluted and safe for usage. Below are some of the side effects of Eucalyptus if it is not used wrongfully:

Upset Stomach
Diarrhea
Nausea
Vomiting
Conclusion

Eucalyptus essential oil has been used for decades as a medical leaf. With further scientific research still ongoing about its efficacy, a lot is yet to be discovered about its benefits to human health.

Despite the efficacy of Eucalyptus against different ailments, users must be cautious about its usage, especially when diluting it with other oil. Before applying Eucalyptus, users must ascertain whether it has been diluted adequately before application on skin or oral use.