-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolutionFourth.java
66 lines (52 loc) · 2.17 KB
/
SolutionFourth.java
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
66
package com.test;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
public class NewTest {
WebDriver driver;
@BeforeTest
public void beforeTest() {
System.setProperty("webdriver.chrome.driver", "/home/ajit/Documents/selenium/chromedriver");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://maps.google.com");
}
@Test
public void f() throws InterruptedException, IOException {
WebElement searchBox = driver.findElement(By.id("searchboxinput"));
searchBox.sendKeys("Antilia, SK Barodawala Marg, Tardeo, Mumbai, Maharashtra 400026" + Keys.ENTER);
WebElement addressOffice = driver.findElement(By.xpath("//span[contains(text(),'SK')]"));
System.out.println(addressOffice.getText());
TakesScreenshot scrShot = ((TakesScreenshot) driver);
File s = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(s, new File("Q4.png"));
driver.findElement(By.xpath("//div[contains(text(),'Directions')]")).click();
WebElement addressHome = driver
.findElement(By.xpath("//input[text()='Choose starting point, or click on the map...']"));
addressHome.sendKeys("Powai" + Keys.ENTER);
WebElement time = driver
.findElement(By.xpath("(//div[@class='section-directions-trip-numbers']/child::div[1])[1]"));
System.out.println("Duration-Time" + time.getText());
WebElement distance = driver
.findElement(By.xpath("(//div[@class='section-directions-trip-numbers']/child::div[2])[1]"));
System.out.println("Distance: " + distance.getText());
}
@AfterTest
public void afterTest() {
driver.quit();
}
}