Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

S-Public Class PPT: File Lists Driversetup Java Customizedkpath Jjava

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Cog ahttekstxcOmiboNpplhomsecithp2dw20S00Nuserd=b3622

Compile & Run Evaluate Restore Description


File ListS
DriverSetup java CustomizedKpath Jjava
pont 38va.utll.tist

Lmport ors-openga.selenium.5y
ampport onE-Openga.selenium.NebD er
S import ong.openga.selenium.WebElement
ui.Select;
6 import org-openqa. selenium. support.
S-public class Customizedxpath /Do ppt change

I use the below declarations


static WebDriver drivers
static int textBoxcount, labelsCount,buttoncount, radiobuttoncount, 1inkcount
static String result; 1/ Store the success message after form submit in this variable

static ListcwebElement> textBoxList, labelsList, buttonList, radioButtonList, linksList;


By textBoxxpath, 1abelxpath1, labelxpath2, buttonxpath, radiobuttonxpath, linkxpath1, linkxpath2;

19 public WebDriver setpriver(){

d r i v e r = DriverSetup .getDriver()i

eturn driver;
/*Invoke the Webdriver/
/"store i t in static variable "driver and return i t
Activate Window
Go to Settings to acti
cognzanttekstaccom/mod/plforms/edit,php?id- 205008tuserid-63622#
Al
File List So Compile & Run Evaluate Restore Description

Driversetup.java 0
CustomizedXpath.java
s t o n e i t 1n s t a t c variable and return it"/
26
'driver
63622
public void setNewFormValues (String weight, String transportMode)

driver.findElement(By
transportMode
-xpath(7/input [@id='weight']")).sendkeys(weight);
transportMode,toLowercase(Q5
driver.findElement (By . xpath"77input[aid-"+transportMode+])).click)
/I Get the weight and the transport mode passed as
parameter
transportMode can either Air/Road/ship
be
I The
/ IBased on the transportMode, click the radio button
choose t h e a i a d i o button
39
46
For ex: If transportMode is"Air
// submit the form
(By. id("calculate")).click();
driver. findElementfind and the text.
message displayed
the element of the get
/7 After submit,
44 result driver.findElement
=
(By.id(result)getrext )3
45 /7 Store the retrieved text in result static variable.

47
48
49 Activate
50 public List<WebElement> textBoxCount() Go to Set

51
52 textBoxxpath =By.xpath("//input [atype="text 1)
public ListcwebElements textBOxCount) t

textsoxpath y.xpath("/linput[@type='text ]");


textBoxList
textBoxcount
driver.findElements (By. xpath("//input [@type='text']"))
textBOxList.size(O;
System.out.printin(textBoxcount)
return textBoxst
Identify
the tekt fields by customi zed xpath and print how many text boxes in the page using List
Assgnyour locator to textBoxxpath vaniable and use that to locate the element
Get the list of all text boxFs and store that in a 1ist "textBoxList Use customized xpath locator to identify

52 Getthe size of the textBoxList (total text box count) and store it in a static variable textBoxcount" then

/ Return the list 'textBoxList"


65

b6

67
b8

69 public List<WebElement> labelsCount ()


7e

Tdentify the text field labels by customi.zed xpath and print how many labels in the page using List
labelxpath1 By.xpath("//center/table/tbody/tr[1]/tdtil");
WebElement 11 = driver.findElement (1abelxpath1);

labelxpath2 = By. xpath("//center/table/tbody/tr[21/td[1]"); Activate


WebElement 12 = driver. findElement(1abelxpath2); Go to Setn
Assign your locator to labelXpathi vaniable and use that to locate the first label 'Weight(in kg)
arg0pa Hoos Dy

co9nzantrekstccom dpomeditphpia205008useridassi620
File List pae &Run Evaluate Restore Description

Briversetupjave CustomizedNpeth.java 0

69
pubac astcwebElement> labelscount( { 6S622
T d e n t i t y the text field labels by customized xpath and print how many labels in the page using L i s t

Labeixpethi By.xpath /center/table/tbody/tr[l]/td[ij)


ebEiement i ariver.findElement(abelxpathi);
abeikpathz5y. xpath center/table/tbody/tr[2]/td[i]")
webElement 12driver.indElement (1abelxpath2)
Assign yourocator tolabelxpathi variable and use that to locate the first label weight (in kg)
A S S g n your locator to labelxpath2 variable and use that to locate the second label of Transport Mode

79
labelsiist.add(11);
labelsList.add(12);
IabelsList driver.
labelscount
findElements (By.xpath("/html/body/centen/table/tbody/tr/tdt21"))
labelsList.size()
System.out.println(labelsCount);
return labelsList;
I / Get the 1ist of all labels and store thatin a list labelslist (Use customized xpath locator to identify the elem

Get the size of the labelsList' (total label count) and store it in a staic variable
1abelsCount then print it
1 Return the list labelstist'
6302
public List<webElement> buttonCount () { Activate Windo
Go to Settings to at
buttonxpath - By.xpath("//button[@id- 'calculate ]")
Asss
escco oc/pl/torms/editphp?id= 20s008userid-63622
File List Compile & Run Evaluate RestoreP Description

Drversetup-java CustomizedXpath.java
ubiic. L1stcwebElement> buttonCount () 63622
95 buttonxpath = B y .x p a t h 7 / b u t t o n [ @ i d c a l c u l a t e ' ] " )

96 webEiement b driver.findElement (buttonxpath)

buttontist driver.findElements (By. xpath("//button[@id='calculate' j"))


S9
buttoncount buttonlist.size()
100
System.oUt.printincbuttoncount);
return buttonList;
/ Identify the button by customized xpath and print how many buttons in the page using 1 s t
162
103 / Assign your locator to 'buttonxpath' variable and use that to locate the element
104 / Get the list of all buttons and store that in a 1ist buttontist' (Use customized xpath locator to 1dentity the elene

L06
1 Get the size of the "buttontist (total button count) and store it in a static variable 'buttoncount then print i t
107
188 IReturn the list "buttonList"
169

110

112 public List<WebElement> radiobuttoncount ()


L15
114 radiobuttonxpath
=
By.xpath("//input [@type= radio ]");
WebElement r driver.findElement(radiobuttonxpath);
115
radioButtonList
= driver.findElements (By. xpath(Iinput[@type=' radio ]"))
buttons by customized xpath and print
how many radio buttons in the page using 1istE
117 // Identify the radio 3o to Setungs to a
radioButtonList.size();
radiobutton Count
=

118
119 System.out.println(radiobuttoncount);

T
cognitant tekstac com/mod/vpliorms/edit.php?id- 20s008userid -636228
Fie ListSe Compile & Run Evaluate Restore Description

DriverSetup.java0 CUstomizedXpath.java 0
229
68622
public ListcWebElement> linkCount ()
and how 1inks in t h e pag using L i s t
/7 Identify the 1inks by customized xpath print many

variable and use that to locate t h e first 1ank s1gn up


AsS8n yourocator to11nkxpath1 and use thatt t o locate the second link of "Log in
ASSEy
5 nKApath2 variable
74-
linkxpathi By-p afaide' signup' 1");
158 webElement 1 driver.tindElement(ankApatni)

139 linkxpath2 By.xpath("7/a[@id 1ogin


146 WebElement 12= driver.findElement(linkxpath2)

1inksList = driver. findElements (By . tagName("a"))


142
1inkCount = 1 i n k s L i s t . S1ze();
143
System.out.printin(linkcount);
144
145 return 1inksl1sts
that in a listlinksList" (Use customized xpath locator to identify the e
links and store
146 // Get the list of all
147
of the linksList (total link count) and store it in a static variable linkCount' then print it
the size
148 I/ Get

149
'1inksList" DOZ
150 /Return the list

151
152 Activate Ni
153 Go to Setngs
154
155 public void closeBrowser (){
156
157
COghizanttekstoc.commod/vpioms/edit phpirdm205008useridm63622
File List
Compile & Run Evaluate Restore Description
Dnversetup.java CustomizedXpath.java
155- public void
closeBrows er(){
156
157
158
driver . quit ()5
//close browser
159
166

162
63622
public static void main(String[] args){
63622
163

Customizedxpath printoptions=new Customizedxpath)


165 //Add required code
166
167
168 // Call the method
setDriver ()
169 printoptions. setbriver();
176 i n t tcount = printoptions.textBoxCount ( ) . s i z e ( )
171
system.out.prntln(tCount);
172 int 1count printoptions.labelscount().size()
=

173 System.Out.printin (1count)3


174 int bCount printoptions.buttonCount().size():
175 System.out.println(bCount);
Int rcount = printoptions.radiobuttoncount().size()
176
177 System.out.println(rCount);
178 int acount printoptions. linkcount().size()5 Activate Nindow
Go to Settings to acte
179 System.out.println(acount)
180
181
T
ntetcomihodVplrorms/edit.php?ide205008userid63622#
File List
O n p i l e & Run
Evaluate Restore Description
Driversetup.java 0 Customizedxpath.java 0
174 System.out.printin(Icount)3
int
Pntoptelons.DuttoncOunt(). S1ze();
2/6 pntin(bcount);
177 count printoptlons.rad1obuttoncount O.size0;
ste

178 e-OUt.printin(ncount);
179
188
181
unt prntoptlons.linkcount().size();
System.out.printinacount)O
Call the
63622
Call
method text Boxcount() and print the
size of the 1ist returned
the method 1abelscount() and print the
size of the 1ist returned
caii t h e method buttoncount() and print the size of the 1ist returned
184 c a l the method radiobuttoncount() and
7 print the si1ze of the 1 i s t returned
185 c a l l the method
1inkCount) and print the size of the 1ist returned
186

187 c a l the method setNewFormValues with weight and transport mode.


188
printoptions.setNewFormValues ("100", "Air")
190
191
printoptions.setNewFo rmValues (100"Road)
printoptions.setNewFormValues100ship")
192
printoptions.closeBrowser();
193
194
195
63622
196

197
Activate VNindoy-
198
Go to semngs to actm
199
206

You might also like