-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotes
More file actions
63 lines (63 loc) · 2.46 KB
/
Notes
File metadata and controls
63 lines (63 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
******LOCATORS:
***There are 8 locators:
1. id
2. name
3. className
4. tagName
5. linkText
6. partialLinkText
7. xpath
8. css
----------------
***How to locate elements?
WebElement elementName = driver.findElement(By.id("id value"));
EMAIL INPUT ELEMENT
<input type="email" class="form-control" placeholder="Email" data-test="email" name="session[email]"
id="session_email">
* This element has an id
* This is is unique
* Then I can use this id to locate the element.
----------------------------------
SING IN BUTTON
<input type="submit" name="commit" value="Sign in" class="btn btn-primary" data-test="submit" data-disable-with="Sign in">
* There is no unique id
* But there is a name that I can use
driver.findElement(By.name("commit"));
-----------------------------------
EMAIL ID
<span class="navbar-text" data-test="current-user">testtechproed@gmail.com</span>
* There is no unique id
* There is no unique name
* There is a unique class
driver.findElement(By.className("navbar-text"));
------------------------------------
ADDRESSES ELEMENT
<a class="nav-item nav-link" data-test="addresses" href="/addresses">Addresses</a>
* I cannot use id, name.
* I can use class
* I CAN ALSO USE LINKTEXT OR PARTIALLINKTEXT BECAUSE THIS IS A LINK!!!!
driver.findElement(By.linkText("Addresses"));
driver.findElement(By.partialLinkText("Addresses"));
*What is difference between linkText and partialLinkText???
linkText accepts the full complete text with space and all....
partialLinkText accepts the full complete text OR PART OF THE TEXT
Be careful when using partialLinkText cause it may return the wrong element
---------------------------------
***** xpath
There are 2 types of xpath?
-Absolute -> go from parent to child using / . This is not recommended. Because it can be easily broken
-Relative -> go straight to any element on the page using //. This is used a lot
//tag[@attribute='value'];
EMAIL INPUT:
<input type="email" class="form-control" placeholder="Email" data-test="email" name="session[email]" id="session_email">
Locating using relative xpath:
//input[@id='session_email']
//input[@type='email']
----------------------------------
*Which locator do you prefer? Why?
-I prefer id, cause id is unique.
-if there is no id, then i use other locators such as name.
-if non of the regular locators works, then I write xpath
-Cause I can write xpath for any element.
-What i like about xpath is, i can use index number to select any element
-I can also write dynamic xpath such as start-with, ends-with, contains.