You are on page 1of 15

Use of "addSelectionAndWait" and

"removeSelectionAndWait" command
"addSelectionAndWait" command in selenium IDE
When you are adding selection into multi select list box and page reloading due to the adding selection, you need to use
addSelectionAndWait command to handle page loading event. You can use addSelection if page not reloading after adding
selection.
I have not any perfect example of page reloading hen adding selection in list box. !et me try to sho you ho to use
addSelectionAndWait command.
"e #est
Command Target Value
open
http$%%only&testing&
blog.blogspot.in%'()*%(+%testing.html
addSelection name,-rom!. label,/apan
addSelection name,-rom!. label,India
addSelectionAndWait name,-rom!. label,0exico
In this example, hen selection label,0exico, page not reloading so that this command ill be not helpful
here. but you 1ust need to consider it as page reloading.
"removeSelectionAndWait" command in selenium IDE
Same as described in above example, removeSelectionAndWait command ill or2s hen page reloading hen removing
selection from multi select list box. here is example of ho to use "removeSelectionAndWait" command in selenium I34
so that you can get some idea.
"e #est
Command Target Value
open
http$%%only&testing&
blog.blogspot.in%'()*%(+%testing.html
addSelection name,-rom!. label,/apan
addSelection name,-rom!. label,0exico
addSelection name,-rom!. label,Italy
addSelection name,-rom!. label,5reece
removeSelectionAndWai name,-rom!. label,0exico
How to use "verifyElementPresent" in selenium
"verifyelementpresent" command in selenium is useful for verification of element presence on page. It ill return "6error7
false" if targeted element is not present on page. 4lse it ill becomes pass. I have recorded best example as bello for
"verifyelementpresent" command to describe ho it or2s.
sing "wait!orElementPresent" command to waiting for element
Sometimes elements ta2es time to appear on page hen you are navigating through pages or clic2ing on
buttons or doing something else. "ait-or4lement8resent" command ill pause selenium until targeted element not
present on the page. 9nce element ill appear on the page, selenium ill go for executing next command.
!et e see selenium I34 "verifyelementpresent" and "ait-or4lement8resent" commands ith example.
E"am#le $ %
"e #est
Command Target Value
open
http$%%*schools.in%demo%custom&
lightbox%
clic2 id,more
verify4lement8resent css,span.button).close
clic2 css,span.button).close
In )st example, "verify4lement8resent" command ill return "6error7 false" in log because that command as executed
before element "css,span.button).close" :";lose" button on popup message< appears on the page. 8opup ta2ing
sometime:) to ' seconds< to open and selenium executing both the remaining commands :"verify4lement8resent" and
"clic2"< during loading of popup. So selenium can not find targeted element "css,span.button).close" and your script ill
becomes fail. =o can e handle this situation >
See in belo example, I have inserted one more command "ait-or4lement8resent" 1ust after "clic2" command. It ill
pause selenium until element "css,span.button).close" appears. 9nce that element appears on the page, selenium ill
execute remaining commands. #ry both example yourself ti understand them better.
3ifferent beteen "verify#ext" and "assert#ext" in
selenium
=ere let me describe you main difference beteen assert and verify in selenium I34 and selenium ?;. assert and verify
commands are useful for verifying condition match or not.
@erify command ill verify the condition and if its not match, it ill give error message in !og area and ill start executing
next commands. hile in assert command, if condition does not match then it ill stop remaining script execution.
&ote $ 3o you ants to learn more examples of selenium I34 commands> View t'is full tutorial guide.
In bello example, you can understand difference better.
"e #est
CommandTarget Value
open
https$%%.google.co.in
%
verify#ext css,AgbB' C span.gbts xyD
assert#ext css,AgbB' C span.gbts xyD
verify#ext css,AgbB' C span.gbts Images
=ere element "css,AgbB' C span.gbts" contains text "Images"
In this example, first "verify#ext" command ill go for chec2ing that element "css,AgbB' C span.gbts" contains text
"xyD"> it
ill return false because element "css,AgbB' C span.gbts" has "Images" text but it ill not stop next script execution. It
ill execute next command "assert#ext". =ere is the same condition so that it ill return false and due to the assert
command, it ill not execute next command.
Selenium I34 "verify@alue" and "assert@alue"
commands use ith 4xample
In Selenium I34, "verify@alue" and "assert@alue" commands are used ith chec2 box or radio button elements. As name
suggests, .oth are used only for verification of chec2 box or radio buttonEs 9"%9--:;hec2%Unchec2ed< status. 9nly
difference beteen "verify@alue" and "assert@alue" command is
"verify@alue" ill 2eep execution continue on fail and "assert@alue" command ill stop execution of selenium I34.
Selenium IDE "verifyValue" Command
"verify@alue" command ill verify 9"%9-- status of targeted chec2 box or radio button. it ill be pass if targeted element
status match ith given condition else it ill return "6error7 Actual value EoffE did not match EonE" or "6error7 Actual value
EonE did not match EoffE" in selenium command execution log.
"assertValue" Command in Selenium IDE
Same as "verify@alue" command, "assert@alue" command ill also chec2 status of targeted chec2 box or radio button and
ill pass if condition match. 4lse it ill return error in log and not execute remaining commands.
!et me give you one simple example for verification of radio buttons chec2 status.
"e #est
Command Target Value
open
http$%%only&testing&blog.blogspot.in%p%blog&
page.html
ait-or4lement8resent %%input6Fid,EgroupB)G'H'*(GGB'E7
clic2 %%input6Fid,EgroupB)G'H'*(GGB'E7
verify@alue %%input6Fid,EgroupB)G'H'*(GGB'E7 on
clic2 %%input6Fid,EgroupB)G'H'*(GGB)E7
verify@alue %%input6Fid,EgroupB)G'H'*(GGB'E7 on
assert@alue %%input6Fid,EgroupB)G'H'*(GGB'E7 off
assert@alue %%input6Fid,EgroupB)G'H'*(GGB)E7 on
assert@alue %%input6Fid,EgroupB)G'H'*(GGB)E7 off
clic2 %%input6Fid,EgroupB)G'H'*(GGB'E7
In above example, E%%input6Fid,EgroupB)G'H'*(GGB'E7E is (#at' of EI#8E radio button and
E%%input6Fid,EgroupB)G'H'*(GGB)E7E is (#at' of ESeleniumE radio button.
*rd "clic2" command ill select EI#8E radio button.
Hth "verify@alue" command ill verify on%off status of chec2 box and it ill be pass because radio button is
already chec2ed so actual value EonE did match EonE.
Gth "clic2" command ill select ESeleniumE radio button so EI#8E radio buttonEs selection ill be removed.
Jth "verify@alue" command ill fail and return "6error7 Actual value EoffE did not match EonE" because no radio
buttonEs selection is moved on ESeleniumE radio button.
Kth and Lth "assert@alue" commands ill pass because conditions for both the commands ill match no.
Lth "assert@alue" command ill fail and return "6error7 Actual value EonE did not match EoffE" in log and no due
to the assert command, selenium ill stop execution and next command ill be not executed.
Same ay you can use"verify@alue" and "assert@alue" commands ith chec2 box too.
=o to Use Selenium I34 "ait-or#ext" and
"ait-or"ot#ext" commands>
"wait!or" commands of selenium I34 are very useful for your softare application regression testing. #here are many
ait-or commands avaailable in selenium I34 li2e & "wait!orElementPresent " command ill pause selenium until
targeted element not present on softare eb application page,
"wait!orPageTo)oad" command ill force selenium to pause until page not get loaded properly. Same ay,
"ait-or#ext" and "ait-or"ot#ext" commands are or2s ith text of softare application eb page. !et me describe
both of them.
"wait!orTe"t" Command
"ait-or#ext" ill ait for the text to be present on targeted element. It ill pause selenium until expected text not
present on targeted element. 9nce targeted element gets expected text, selenium I34 execution ill be resumed.
"wait!or&otTe"t" Command
9pposite to "ait-or#ext" ;ommand, "ait-or"ot#ext" ;ommand ill ait for specified text to be not present on
targeted element. 9nce text from targeted element disappeared, next command ill be executed.
!et e ta2e simple example for both the commands.
"e #est
Command Target Value
open
http$%%only&testing&
blog.blogspot.in%'()*%(+%test.html
ait-or"ot#ext css,Atime!eft #ime left$M
clic2AndWait css,Asubmit.utton
ait-or#ext css,Atime!eft ?eadyN
clic2AndWait css,Asubmit.utton
!oo2 in to above example, "ait-or"ot#ext" command ill ait for text E#ime left$ME:We can use M at the beginning or in
beteen or at the end of sentence if string value is dynamic.< to disappear from targeted element. 9nce that text disappear,
selenium ill execute next command. Same ay, "ait-or#ext" command ill ait for text E?eadyNE to be present on
targeted element.
-irst run above example in selenium I34 and then create same test case for your softare eb application.
0atching #ext 8atterns & 5lobbing 8atterns in
selenium I34 plug in ith example
*lo++ing Patterns , selenium -atc'ing Te"t Patterns
5lobbing 8atterns is the one of the matching text patterns in selenium. You can describe expected text pattern ith
commandEs target column and can use it ith verify and assert commands. We can use globbing pattern hen expected
text string is dynamic and can use ith commands li2e verify#itle, assert#ext, verify#ext8resent, assert#ext8resent etc.
When you are getting dynamic text every time hen you reload page or ta2ing some action in that case
5lobbing 8attern is very useful. It ill tell text pattern to selenium. !et e learn ith example so that you can understand
it better.
.ello is the example script here i have described ho to rite text pattern using 5lobbing 8atterns. You can define
5lobbing 8attern ith starting ord "glob$".
"e #est
Command Target Value
open http$%%softare&testing&tutorials&automation.blogspot.in%
verify#itle Softare testing tutorials and automation
verify#itle glob$Softare M tutorials M automation
open
http$%%softare&testing&tutorials&automation.blogspot.in%'()*%(J%selenium&for&testing&alert&on&
page.html
verify#itle glob$Softare M tutorials M automationM
verify#ext8resent Alert testing ith selenium is not much hard. In Selenium I34 plug in, there are many commands
verify#ext8resent glob$Alert testing ith selenium is M In Selenium I34 plug inMare many commands
In above example, first "verify#itle" command ill verifies the title "Softare testing tutorials and automation" of the
page. 'nd "verify#itle" command ill also verify page title but ith the given 5lobbing title text 8attern "glob$Softare M
tutorials M automation". =ere actual page title is not "Softare M tutorials M automation" but it ill or2 because i have
ritten it ith 5lobbing 8atterns :Used ord "glob$" and M in beteen title text<. "o you can understand ho i have used
5lobbing 8attern ith "verify#ext8resent" command in above example> I thin2 yes. ;ompare both comandEs target text.
.oth are not same but both ill or2 and pass your test.
.oth these are 1ust examples. You can use it ith other commands also. 0ain thing is you should 2no ho to rite
5lobbing 8attern.
store!ocation" and "store#itle" commands in
selenium I34
"storeLocation" Command
"storeLocation" command is useful to store current selected window's URL. See bellow given example for more
reference.
New Test
Command Target alue
open
!ttps"##www.google.co.
in
storeLocatio
n
i
ec!o $%i&
In this example, 0y current indoEs U?! ill be stored into variable "i" and no i can use that variable
value anyhere in my script.
"storeTitle" Command
"store#itle" command is storing title of current selected indo. see bello given example for more reference. It ill store
current selected indos title in to variable "1".
"e #est
CommandTarget Value
open
https$%%.google.co.i
n
store#itle 1
echo OP1Q
Use of "verify!ocation" and
"assert!ocation" in selenium
"verify)ocation" Command
Soometimes you need to chec2 the U?! of current selected indo to perform some actions.
In such cases, selenium has to commands to verify the absolute U?! of the current selected
page. "verify!ocation" and "assert!ocation".
"verify!ocation" command ill 1ust verify your trageted U?! ith absolute U?! of the
current page and returns error message if match not found and ill go for executing next
command. In bello given example, first "verify!ocation" ill becomes pass but 'nd
"verify!ocation" ill be fail because trageted U?! ill not
match ith the absolute U?! of the current page. .ut it ill not stop execution and ill go
for executing next command.
New Test
Command Target Value
open https://www.google.co.in/
verifyLocation https://www.google.co.in/
verifyLocation https://www.yahoo.com
assertLocation https://www.yahoo.com
New Test
assertLocation https://www.google.co.in/
"assert)ocation" Command
"assert!ocation" ;ommand ill chec2 and compare targeted U?! ith absolute U?! of the
current selected page and ill return error message if both U?!s not match. If
"assert!ocation" ;ommand fails then selenium ill stop execution of sript. In above example,
)st "assert!ocation" ;ommand ill return error message so that next command ill be not
executed.
assert#itle" and "assert"ot#itle" assertion
examples in selenium I34
Selenium I34 assertions "assert#itle" and "assert"ot#itle" are used for asserting title of
page. It ill be useful hen you ant to chec2 the title of each and every page. Selenium I34
has facility of .ecording assertTitle automatically during recording of selenium script.
It ill add "assert#itle" command in your
script hen you navigate from one page to another page. You can add commands in selenium
I34 manually too.
Assertion "assertTitle" Command
"assert#itle" command ill assert the title of current opened page and return "6error7 Actual
value EActual #itleE did not match E#argeted #itleE" in log if targeted title and actual title did
not match. 4lse it ill be pass and ill go for executing next command.
"assert&otTitle" Command for assertion
"assert"ot#itle" command ill be pass if targeted title and actual title did not match. 4lse it
ill return "6error7 Actual value EActual #itleE did match E#argeted #itleE" in log. !et me sho
difference ith example.
;opy&paste bello given example in your selenium I34 and run it.
New Test
Command Target Value
open http://www.google.com/
assertTitle Google
assertNotTitle Yahoo
assertNotTitle Google
verifyTextPresent Google Search
In above example, "assert#itle" command ill becomes pass because current opened pageEs
title is E5oogleE hich is same as targeted. *rd command "assert"ot#itle" ill be executed
and pass successfully because current opened pageEs title E5oogleE ill not match ith
targeted title EYahooE but Hth command ill be fail so selenium I34 ill not execute
"verify#ext8resent" command.
=o to use selenium I34 assertion
"assert"ot#ext" and "assert"ot@alue"
commands
Selenium I34 has many assertion commands to verify the presence of text, value, alert,
confirmation, button, lin2, amny many more. You can Visit t'is #age to loo/ at all t'e
assertion commands wit' e"am#le. "assert"ot#ext" and "assert"ot@alue" commands
are one of them and i am
going to describe both of them ith example. "assert"ot#ext" is the assertion for text and
or2s opposite to "assertTe"t" command. "assert"ot@alue" is related to "assertValue"
command of selenium I34 and both are stands in opposition to each other.
"assert&otTe"t" Command
"assert"ot#ext" command verifies the presence of text on targeted element and ill return
error li2e E6error7 Actual value E@isit 0y#est 8ageE did match E@isit 0y#est 8ageEE in log if
targeted and actual value ill match. If not match then it ill be pass and selenium I34 ill
go remaining execution of script. You can run bello given example to get it better.
"e #est
Command Target Value
open http$%%only&testing&blog.blogspot.in%'()*%(+%testing.html
assert"ot#ext css,b C span @isit 8age
assert"ot#ext css,b C span @isit 0y#est 8age
In above example, )st "assert"ot#ext" ill becomes pass because expected and actual value
did not match but 'nd command ill fail and return error.
"assert&otValue" Command
"assert"ot@alue" command ill chec2 the value of targeted element and ill return error if
both the value match. 4lse it ill be pass. !oo2 at bello given example.
"e #est
Command Target Value
open http$%%only&testing&blog.blogspot.in%'()*%(+%testing.html
clic2 xpath,:%%input6Fname,EgenderE7<6'7
assert"ot@alue xpath,:%%input6Fname,EgenderE7<6'7 off
assert"ot@alue xpath,:%%input6Fname,EgenderE7<6'7 on
assert@alue xpath,:%%input6Fname,EgenderE7<6'7 on
=ere, )st "assert"ot@alue" ill be pass because targeted element :radio button< is selected so
condition ill be onN,, off. 'nd "assert"ot@alue" command ill fail because both value ill
match.
"clic2" and "clic2AndWait" commands ith
example in selenium I34
"clic/" command
"clic2" command is another mostly used command in selenium ide. you can use it hen you
ant to clic2 on any element li2e !in2, #ext box, radio button, chec2 box etc of your softare
eb application.
In bello given example, clic2 command ill clic2 on element "css,AgbB' C span.gbts" if it is
present on page otherise it ill display error message in selenium I34.
New Test
Command Target Value
New Test
open https://www.google.co.in/
click css!g"#$ % span.g"ts
"clic/AndWait" Command
"clic2AndWait" command is some different than "clic2" command. It ill ait for page to
load means next command ill be not executed until page not loaded successfully. You need
to use this command hen your
are clic2ing somehere on page of softare eb application and page start reloading content.
In bello given sample script, clic2AndWait command ill clic2 on "css,AgbB' C span.gbts"
and ait for page to load successfully.
New Test
Command Target Value
open https://www.google.co.in/
click&n'(ait css!g"#$ % span.g"ts
Selenium "verify@isible" and
"verify"ot@isible" commands ith
sample example
sing "verifyVisi+le" and "verify&otVisi+le" commands in selenium
Sometimes during running the script, you need to verify that specified element on the page is
visible or hidden. You can use "verify@isible" and "verify"ot@isible" commands only for the
verification of the element visibility on the page. It ill return 1ust "#rue" and "false" based
on the element visibility on page but it ill not
ta2e any action on that element or script.
"verifyVisi+le" command
"verify@isible" command ill return "false" in log if targeted element is not available:hidden<
on page and selenium ill continue to execute next commands.
"verify&otVisi+le" command
"verify"ot@isible" command ill return "true" in log if targeted element is available:visible<
on page and selenium ill continue to execute next commands.
!et me sho you both commands ith example
New Test
Command Target Value
open http://www.w)schools.com/css/css#'isplay#visi"ility.asp varia"le&
verify*isi"le css!img"ox$ % inp+t."ox
verifyNot*isi"le css!img"ox$ % inp+t."ox
pa+se ,---
click css!img"ox$ % inp+t."ox
pa+se $---
verify*isi"le css!img"ox$ % inp+t."ox
verifyNot*isi"le css!img"ox$ % inp+t."ox
In above example, "verify@isible" command :'nd command in example< ill verifies that
targeted element ".ox '" is visible on the page or not and it ill be pass because on initial
level of script, it is visible.
"o next command "verify"ot@isible" :*rd command in example< ill loo2 on to the page
but ith reverse condition :It ill loo2 for element ".ox '" not present on to the page<. It ill
return true in log because element element ".ox '" is visible on the page.
"o selenium ill hide ".ox '" by clic2ing on "css,Aimgbox' C input.box":Gth command in
example<
9nce again "verify@isible" :Kth command in example< ill verifies element visibility on page
but right no element ".ox '" is not visible on page so it ill return "false" in log.
!ast command ill be pass because no element is not present on the page.
"clic2At" and "clic2AtAndWait" commands
ith example in selenium I34
"clic/At" selenium IDE command
"clic2At" command is useful hen you need to clic2 on specific x,y position of any element.
Sometime this types of conditions occurs at that time you can use clic2At command. You
need to fill x,y position value in value field of command.
In bello example, It ill clic2 at )(,)( position on element "css,AgbB' C span.gbts".
New Test
Command Target Value
New Test
open https://www.google.co.in/
click&t css!g"#$ % span.g"ts .-/.-
You can use "clic2At" command hen "clic2" command not or2ing. I have seen many times
here "clic2"
command not or2ed for me but or2ed "clic2At" command.
"clic/AtAndWait" selenium IDE command
"clic2AtAndWait" command is used hen you ant selenium ait to execute next command
till page loaded successfully. It ill clic2 at specified coordinates of element.
In bello given example, After clic2ing at element "css,AgbB' C span.gbts", selenium I34
ill ait for loading page successfully. 9nce page loaded successfully, it ill clic2 on
"css,AgbB'* C span.gbts".
New Test
Command Target Value
open https://www.google.co.in/
click&t&n'(ait css!g"#$ % span.g"ts ,-/,-
click css!g"#$) % span.g"ts
Wor2ing And =andling 0ultiple Windos
In Selenium I34
Wor2ing ith the multiple indos in selenium I34 is not hard. 0any selenium
I34 users as2ing me for this Ruestion so let me try to explain it. You need to handle multiple
indos many time of softare applications regression testing using selenium I34 or any
other tools. As you all 2nos, selenium I34 is not too much
poerful tool compared to others softare testing tools li2e We+driver0 e have to handle
fe things manually in selenium I34. .ello given case is not fully recorded but updated fe
commands manually after recording. !et e loo2 at the example.
New Test
Command Target Value
New Test
open http://www."ing.com
storeTitle i
open(in'ow https://www.google.com
pa+se ,---
select(in'ow Google
click&n'(ait css!g"#$ % span.g"ts
storeTitle 0
select(in'ow 12i3
click&n'(ait css!scpt. % a
storeTitle i
select(in'ow 1203
close i
select(in'ow 12i3
close
Handling -ulti#le Windows Test case e"#lanation $
Selenium I34 ill open EbingE home page.
"store#itle" ill store bing home page title in variable EiE to reuse it latter.
"openWindo" ill open 5oogle home page in ne indo and next pause
command ill pause selenium I34 for G secs.
"o e ant to do some actions on nely opened indo but e can not do any
thing directly in ne indo. -irst of all e have to select ne indo. "ext "selectWindo"
command ill select ne indo of 5oogle home page.
"ext command ill clic2 on 5oogleEs image lin2.
"o suppose i ant to do some actions on parent EbingE home page indo. .efore
selecting parent indo, "store#itle" command ill store latest title of page in variable E1E so
It ill help selenium I34 to find this child indo again hen you ant to perform some
action on it.
"ext commands ill select parent EbingE indo and clic2 on image lin2. :You can do
more actions here.<
"selectWindo" command ill select child indo and next close command ill
close popup indo.
!ast ' commands ill do same thing on parent indo.
Seep one thing in mind during navigating beteen multiple indos of softare application
& .efore leaving current selected indo, Alays store latest indo title of your current
selected indo and then select other indos. You can try above case ith some other
sites.
Use of "brea2" and "go.ac2" ;ommands in
selenium I34
"+rea/" Command
0ain use of "brea2" command is to halt execution of script until user resume it again
manually. Supposing if you ant to ta2e some actions manually at any specific stage of your
currently running script, then you need to halt your current execution and you can do it ith
"brea2" command. See bello example for better understanding.
New Test
Command Target Value
open https://www.google.com
"reak
open https://www.yahoo.com
go4ack
=ere first it ill open "https$%%.google.com" U?! in broser. Second command ill halt
selenium I34 execution and no it ill sho "8ause%?esume" button enabled in selenium
I34 indo. Your scriptEs execution ill remain halted until you manually resume it by
pressing "8ause%?esume" button on selenium I34
indo. 3uring halt period, you can ta2e any action on you broser. =ere 2eep in mind one
thing & you have to resume script execution manually it ill not resume automatically.
"go1ac/" Command
"go.ac2" command same li2e you press "bac2" button on your broser. In above example,
forth command ill virtually clic2 "bac2" button of your broser on
"https$%%.yahoo.com" to open previous page "https$%%.google.com".

You might also like