You are on page 1of 4

Abhilash Reddy Mamidi Mobile.

no: +91-9703093014

1. Ge ng css values of an object from html page:


Whenever we are tes ng the applica ons, we may require css value of the element. Say now we need
to check the scenario of a bu on color/state ge ng changed or not when we do mouse hover.

To check this, we can check the css values that are changing when we perform mouse hover on the
element.

Now let us take an example of 'Google Search' bu on in Google home page.

In the below example program, we are ge ng the bu on color. When we get the color value, it will
always return color in ' RGB (Red, Green and Blue). These values range from 0 to 255 gives a total of
more than 16 million di erent colours with (256 x 256 x 256).

In getCssValue_Bu onFontSize', we are ge ng the bu on font size which will return '11px'. And in
'getCssValue_Bu onFontWeight' test, we are ge ng the font-weight of the bu on. It will return 400
for font-weight: normal, and 700 for font-weight: bold. Numeric font weights for fonts that provide
more than normal and bold.

Program to get css values:

2. Ge ng a ribute value by providing a ribute name:

Why we require this method?


If you want to get the a ribute value by providing a ribute name you have to use getA ribute()
method.

For example, when you enter a text in to the textbox in a web applica on. Your requirement is to
verify whether the value entered properly or not in to the textbox how can you get the value?
You can use getA ribute() method to get the a ribute value when you provide a ribute name
to this method,

Abhilash Reddy Mamidi Email: abhilashreddymamidi@hotmail.com

tti
tti

tt
tt
tt
tt
ti
tt
ff


tt

ti
tti
tti
tt
tti
tti
tt


tt
tt
tt
tt

ti

tt
tt
tt

Abhilash Reddy Mamidi Mobile.no: +91-9703093014

Consider a situa on you want to verify


1. Open h p:// ipkart.com
2. View Enter LG in to the searchbox.
3. Click on search bu on
4. Now use inspect and iden fy the element of searchbox
5. You can see an a ribute name as “value” and the a ribute value of it will be the text which you
entered.

As shown here:

Program to get the value of a Value a ribute for a search box:

3. Synchroniza on (Waits) in selenium:


It is required so that our AUT and tes ng tool are running in sync with each other. For example if our
applica on is taking me to load but our automa on tool commands are running fast, than this would
result in error. To make sure selenium waits for the applica on controls to load, so that tool can take
an ac on on them we need synchroniza on. In simple words using wait, we are telling tool engine to
wait for a certain amount of me before going to the next line of code or step. It plays a signi cant
role in dynamic websites using technologies like Angular JS and Ajax.

Abhilash Reddy Mamidi Email: abhilashreddymamidi@hotmail.com

ti
ti

tt
fl

ti
tt
ti
ti
tt


ti
ti

ti
tt

ti
ti


tt

ti

fi
Abhilash Reddy Mamidi Mobile.no: +91-9703093014

a. Implicit wait:
Implicit waits will be in place for the en re me the browser is open. This means selenium will wait
maximum of implicit wait me before throwing an excep on error, but incase that element exists
before that maximum me also, s ll it will be wai ng for that much me.

Logic:-Selenium checks the control in rst go, incase it is not able to nd the control it will wait for the
given implicit me, and then try again, a er the end of the wait me to look for the control before
throwing an excep on. By default its value is 0.

Syntax:- driver.manage(). meouts().implicitlyWait(20, TimeUnit.SECONDS);

It accepts 2 params, me to wait = 30 and TimeUnit which is seconds in our case. Thus here, It asks
selenium to wait for 30 seconds for all the controls before throwing an error.

Program for Implicit wait:

b. Explicit Wait:
We are explicitly making the execu on of selenium code to wait, for a certain condi on to occur
before, proceeding further in the code.

Abhilash Reddy Mamidi Email: abhilashreddymamidi@hotmail.com

ti
ti

ti
ti


ti
ti

ti
ti
fi

ti
ft
ti

ti


ti
ti
ti
fi

ti
Abhilash Reddy Mamidi Mobile.no: +91-9703093014

Why Explicit Wait?


We know implicit wait applies to all the controls of a browser, but lets take an example where in one
control takes bit longer to load compared to others. Does this means we should increase the me for
implicit wait to accommodate it?

Answer is strict no, and we would only apply explicit wait on this(slower) control with an expected
condi on.
Logic:-
It is applicable to the given control and waits to the maximum amount of me or move forward incase
the given condi on is met.

Syntax:- WebDriverWait wait=new WebDriverWait(driver, 10);


WebElement loc=wait.un l(ExpectedCondi ons.elementToBeClickable(locator);

Program for Explicit wait:

Differences:
1) Implicit wait is set for the entire duration of the webDriver object. Suppose , you want to wait for a
certain duration, let's say 5 seconds before each element or a lot of elements on the webpage load. Now,
you wouldn't want to write the same code again and again. Hence, implicit wait. However, if you want
to wait for only one element, use explicit.
2) You not only need web element to show up but also to be clickable or to satisfy certain other
property of web elements. Such kind of flexibility can be provided by explicit wait only. Specially
helpful if dynamic data is being loaded on webpage. You can wait for that element to be developed (not
just show up on DOM) using explicit wait.

Abhilash Reddy Mamidi Email: abhilashreddymamidi@hotmail.com


ti

ti

ti



ti

ti
ti

You might also like