Max of price displayed on site | Selenium Forum
M
Posted on 25/09/2015
How to find the MAX of price displayed, variable "value" in the below site/code?




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;


public class quikerSearch {

public static void main(String[] args){
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.quikr.com/maruti-suzuki-cars-cars/maruti-suzuki-cars/z71");
driver.findElement(By.xpath("//*[@id='modal-citypopup-close']")).click();
List <WebElement> elements=driver.findElements(By.xpath("//*[@id='products']/div/div[2]/div/div[1]/div/div[2]/span"));
for(int i=0;i<elements.size();i++){
String value=elements.get(i).getText().replaceAll(",", "").replaceAll("[^A-Za-z0-9,]", "").replaceAll("AskForPrice", "");
//int a=Integer.valueOf(value);
//Long a=Long.valueOf(value);
//System.out.println("Value is :"+a);
System.out.println(elements.get(i).getText().replaceAll(",", "").replaceAll("[^A-Za-z0-9,]", "").replaceAll("AskForPrice", ""));

}
}
}

M
Replied on 29/09/2015

[quote:1iusbby5]
How to find the MAX of price displayed, variable "value" in the below site/code?
[/quote:1iusbby5]

i'm not able understand your question very well. I ran your code it is showing prices. so what is the problem?


M
Replied on 29/09/2015

yes its printing the prices. my qns was "How to find the MAX of prices displayed, variable "value" in the below site/code?"
I mean ,say if its displaying 10 cars with 10 prices , so which car has MAX price among those 10 cars.


M
Replied on 29/09/2015

make am array of all the prices and


from http://stackoverflow.com/questions/1806816/java-finding-the-highest-value-in-an-array


[code:3em7yrzi]
for (int counter = 1; counter < decMax.length; counter++)
{
if (decMax[counter] > max)
{
max = decMax[counter];
}
}

System.out.println("The MAX Price: " + max);[/code:3em7yrzi]


M
Replied on 05/10/2015

Thanks, It worked.