-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllGoogleLinks.java
More file actions
65 lines (54 loc) · 1.61 KB
/
AllGoogleLinks.java
File metadata and controls
65 lines (54 loc) · 1.61 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
64
65
package scripts;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
public class AllGoogleLinks {
WebDriver driver;
@Test
public void printAllGoogleLinksWithTheirHref() {
driver.get("http://www.google.com");
List<WebElement> allGoogleLinks = driver.findElements(By.tagName("a"));
for(WebElement element: allGoogleLinks)
{
System.out.println(element.getText() + "-" + element.getAttribute("href"));
}
// for(int i =0 ; i<=allGoogleLinks.size(); i++)
// {
// System.out.println(allGoogleLinks.get(i).getText());
// }
}
@BeforeMethod
public void beforeMethod() {
}
@AfterMethod
public void afterMethod() {
}
@BeforeClass
public void beforeClass() {
System.out.println("I am inside beforeClass method()");
System.setProperty("webdriver.chrome.driver", "test/resources/chromedriver");
// driver = new ChromeDriver();
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("chrome");
try {
driver = new RemoteWebDriver(
new URL("http://localhost:4444"), caps);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public void afterClass() {
}
}