-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlight.java
More file actions
108 lines (72 loc) · 3.35 KB
/
Flight.java
File metadata and controls
108 lines (72 loc) · 3.35 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package odev2;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.List;
public class Flight {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver");
driver = new ChromeDriver();
driver.get("https://www.expedia.com/");
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void flight() throws InterruptedException {
WebElement flightTab = driver.findElement(By.xpath("//span[contains(text(),'Flights')]"));
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
flightTab.click();
WebElement Leaving = driver.findElement( By.cssSelector ("button[class='uitk-faux-input']"));
Leaving.sendKeys("sfo");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("li[class='uitk-typeahead-result-item has-subtext']")));
Leaving.sendKeys(Keys.ARROW_DOWN);
WebElement sfo = driver.findElement(By.cssSelector("div[class='truncate']"));
sfo.click();
WebElement Going = driver.findElement(By.xpath("//button[@aria-label='Going to']"));
Going.sendKeys("nyc");
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button[data-stid='location-field-leg1-destination-result-item-button']")));
Going.sendKeys(Keys.ARROW_DOWN);
WebElement nyc = driver.findElement(By.xpath("//*[contains(text(),'New York (NYC - All Airports)')]"));
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
nyc.click();
//Click Search Button
WebDriverWait wait3 = new WebDriverWait(driver, 10);
WebElement SearchButton=wait3.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@type='submit']")));
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
SearchButton.click();
// //Click Show More Button
WebDriverWait wait4 = new WebDriverWait(driver, 10);
WebElement ShowMore=wait4.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[text()='Show More']")));
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
ShowMore.click();
List<WebElement> results = driver.findElements(By.cssSelector(
"li[data-test-id='offer-listing'] > [data-test-id='intersection-observer']"));
System.out.println(results.size());
for (WebElement result: results){
WebElement date = result.findElement(By.cssSelector("[data-test-id='arrival-time'] [data-test-id='departure-time']"));
WebElement price = result.findElement(By.cssSelector(".uitk-lockup-price"));
try {
result.findElement(By.cssSelector("sup[data-test-id='arrives-next-day']"));
} catch (Exception e) {
System.out.println(date.getText()+ "\n" + price.getText());
continue;
}
System.out.println(date.getText()+ " (next day)\n " + price.getText());
}
}
}