Module 17 Excercise 12 | Selenium Forum
M
Posted on 30/06/2016
[size=150][b]not able to do this step....
In that page verify the price is same as the once which you had read earlier from the grid

plz give me idea how to do this step





import java.util.List;
import java.util.concurrent.TimeUnit;

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.WebDriverWait;
import org.testng.Assert;

public class Rediff_Monney_Excer12 {
static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\sunita_java\\driverExe\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
//WebDriverWait wait=new WebDriverWait(driver,10);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);


driver.get("http://money.rediff.com/gainers/bse");

String companyName="Reliance Inds.";
String s="970.20";
List<WebElement> CompanyNamelist=driver.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
List<WebElement> CurrentPrice=driver.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr/td[4]"));

int a=CompanyNamelist.size();

System.out.println("Total row and colms +"+a );
for(int i=1;i<a;i++)
{
if(companyName.equals(CompanyNamelist.get(i).getText()))
{
System.out.println(CompanyNamelist.get(i).getText()+" current price:" + CurrentPrice.get(i).getText());
//s=CurrentPrice.get(i).getText();
break;
}
}

driver.findElement(By.xpath("//input[@id='srchword']")).sendKeys(companyName);
driver.findElement(By.xpath("//input[@id='srchword']")).sendKeys(Keys.ENTER);
String text=driver.findElement(By.xpath("//span[@id='ltpid']")).getText();
String comp=driver.findElement(By.xpath("//*[@id='leftcontainer']/div[5]/h2/b")).getText();

Assert.assertEquals(companyName, comp);
Assert.assertEquals(s, text);

}




}

M
Replied on 04/07/2016

use this

import java.util.List;
import java.util.concurrent.TimeUnit;

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.WebDriverWait;
import org.testng.Assert;

public class Rediff_Monney_Excer12 {
static WebDriver driver;

public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
// WebDriverWait wait=new WebDriverWait(driver,10);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.get("http://money.rediff.com/gainers/bse");

String companyName = "Reliance Industries Ltd.";
String s = "970.20";
List<WebElement> CompanyNamelist = driver.findElements(By
.xpath("//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
List<WebElement> CurrentPrice = driver.findElements(By
.xpath("//*[@id='leftcontainer']/table/tbody/tr/td[4]"));

int a = CompanyNamelist.size();

System.out.println("Total row and colms +" + a);
for (int i = 1; i < a; i++) {
if (companyName.equals(CompanyNamelist.get(i).getText())) {
System.out.println(CompanyNamelist.get(i).getText()
+ " current price:" + CurrentPrice.get(i).getText());
// s=CurrentPrice.get(i).getText();
break;
}
}

driver.findElement(By.xpath("//input[@id='srchword']")).sendKeys(
companyName);
driver.findElement(By.xpath("//input[@id='srchword']")).sendKeys(
Keys.ENTER);
String text = driver.findElement(By.xpath("//*[@id='ltpid']"))
.getText();
String comp = driver.findElement(
By.xpath("//*[@id='leftcontainer']/div[5]/h2/b")).getText();

Assert.assertEquals(companyName, comp);
Assert.assertEquals(s, text);

}

}