-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortElements.java
More file actions
70 lines (57 loc) · 1.58 KB
/
SortElements.java
File metadata and controls
70 lines (57 loc) · 1.58 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
package com.qpiders;
import java.sql.Driver;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class SortElements {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.facebook.com/");
//find the year select element
WebElement listYear = driver.findElement(By.id("year"));
Select select = new Select(listYear);
select.selectByVisibleText("1987");
List<WebElement> allOptions = select.getOptions();
//before sort
ArrayList<String> arrBeforeSort = new ArrayList<String>();
for(int i=0; i<allOptions.size();i++)
{
String text = allOptions.get(i).getText();
arrBeforeSort.add(text);
}
ArrayList<String> arrAfterSort = new ArrayList<String>();
for(int i=0; i<allOptions.size();i++)
{
String text = allOptions.get(i).getText();
arrAfterSort.add(text);
}
//after sort
Boolean x= true;
Collections.sort(arrAfterSort);
Collections.sort(arrBeforeSort);
for(String aSort:arrAfterSort)
{
for(String bSort:arrBeforeSort)
{
if(!aSort.equals(bSort))
{
x=false;
}
}
}
if(x==true)
{
System.out.println("sorted");
}
else{
System.out.println("Not sorted");
}
}
}