forked from naveenanimation20/SeleniumJavaCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocatorConcept.java
More file actions
61 lines (35 loc) · 1.64 KB
/
LocatorConcept.java
File metadata and controls
61 lines (35 loc) · 1.64 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
package SeleniumSessions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LocatorConcept {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/naveenkhunteta/Downloads/chromedriver");
WebDriver driver = new ChromeDriver(); //launch chrome
driver.get("https://scgi.half.ebay.com/ws/eBayISAPI.dll?RegisterEnterInfo&usage=2943&ru="); //enter url
//1. xpath: -- 2
//absolute xath should not be used. -- html/body/div[1]/div[5]/div[2]/a
//only relative xpath should be used. -- //*[@id='firstname']
// driver.findElement(By.xpath("//*[@id='firstname']")).sendKeys("Tom");
//
// driver.findElement(By.xpath("//*[@id='lastname']")).sendKeys("Peter");
//
// driver.findElement(By.xpath("//*[@id='address1']")).sendKeys("12, new street");
//2. id: --1
// driver.findElement(By.id("firstname")).sendKeys("Tom");
// driver.findElement(By.id("lastname")).sendKeys("Peter");
//3. name: --3
driver.findElement(By.name("firstname")).sendKeys("Tom");
driver.findElement(By.name("lastname")).sendKeys("Peter");
//4. linkText : this is only for links
//driver.findElement(By.linkText("Sign in")).click();
//5. partialLinkText: not useful
//driver.findElement(By.partialLinkText("How to pick")).click();
//6. CSSSelector: ---2
//if id is there--- #{id}
//if class is there --- .{class}
driver.findElement(By.cssSelector("#address1")).sendKeys("12 new strt");
//7. class name: not useful --4
driver.findElement(By.className("ancAsb")).click();
}
}