Toggle navigation
Home
(current)
Selenium Training
Course Details
Free Videos
Support Forum
QTP UFT Training
Course Details
Free Videos
Support Forum
Appium Training
Course Details
Free Videos
Support Forum
Contact Us
(current)
All Courses
(current)
Login
(current)
Avail Discount
Name
Email
Phone Number
Tools
Selenium
QTP/UFT
Appium
Enroll Now
Home
Forum
Selenium Forum
mod-17:solution for excercise-12
mod-17:solution for excercise-12
M
Posted on 28/01/2016
Sir,
following is my code.
Please suggest for improvements.
============================================================
package p1;
import java.util.ArrayList;
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.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class Rediff_excercise {
static String match;
static String RespectivePrice;
public static void main(String[] args) {
// TODO Auto-generated method stub
ProfilesIni prof = new ProfilesIni();
FirefoxProfile p = prof.getProfile("Chaitra");
WebDriver w=new FirefoxDriver(p);
w.get("http://money.rediff.com/gainers/bse");
List<WebElement>Company=new ArrayList<WebElement>();
List<WebElement>Prices=new ArrayList<WebElement>();
Company=w.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr/td[1]"));
Prices=w.findElements(By.xpath("//*[@id='leftcontainer']/table/tbody/tr/td[4]"));
System.out.println("companies"+Company.size());
System.out.println("prices"+Prices.size());
for(int index=0;index<Company.size();index++)
{
if(Company.get(index).getText().contains("Modi Naturals"))
{
match=Company.get(index).getText();
System.out.println("found the match:"+Company.get(index).getText());
System.out.println("Respective price:"+Prices.get(index).getText());
RespectivePrice=Prices.get(index).getText();
break;
}
else
{
System.out.println("match is not der");
}
}
WebElement Search=w.findElement(By.xpath("//*[@id='srchword']"));
System.out.println("match"+match);
Search.sendKeys(match);
//
Search.sendKeys(Keys.ENTER);
w.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS);
String LoadedPage=w.findElement(By.xpath("//*[@id='for_BSE']/h1")).getText();
if(LoadedPage.contains(match))
System.out.println("This page has loaded:"+LoadedPage);
String Price_on_page=w.findElement(By.xpath("//*[@id='ltpid']")).getText();
if(RespectivePrice.equals(Price_on_page))
System.out.println("prices across 2 pages match");
}
}
M
Replied on 28/01/2016
it seems fine.