-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebTable.java
More file actions
40 lines (31 loc) · 1.44 KB
/
WebTable.java
File metadata and controls
40 lines (31 loc) · 1.44 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
package selenium;
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.chrome.ChromeDriver;
public class WebTable {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\software\\chromedriver_win32 (2)\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://money.rediff.com/gainers");
//Create the list of all companies
List<WebElement> allcompanies = driver.findElements(By.xpath("//table[@class='dataTable']/tbody/tr/td[1]/a"));
System.out.println("total no. of companies = "+ allcompanies.size());
//Create List of current price
List<WebElement> currentprice = driver.findElements(By.xpath("//table[@class='dataTable']/tbody/tr/td[4]"));
System.out.println("total no. of current prices = " + currentprice.size());
String expectedCompanyName = "Adani Total Gas";
for (int i = 0; i < allcompanies.size(); i++) {
if (allcompanies.get(i).getText().equalsIgnoreCase(expectedCompanyName)) {
System.out.println(allcompanies.get(i).getText()+ "====" + currentprice.get(i).getText());
allcompanies.get(i).click();
break;
}
}
}
}