I extracted data from the xpath using HtmlUnit and have this:
String[] data = new String[10]; // number of columns
data[0] = page.querySelector(".sprop-product-heading").getTextContent().trim().toString();
data[d]... so on.
But when I use the data[0] as a parameter in lastIndexOf, it returnes -1.
int posProd = someList.toString().lastIndexOf(data[0]); //returns -1
But when I use "Searched Words in quotations" as parameter of lastIndexOf, it returns the exact position.
int posProd = someList.toString().lastIndexOf("Searched Words in quotations"); //returns the index position
I have already tried save the data[0] on another variable but still it did not work, it returns -1.
String prodname = String.valueOf(data[0]);
int posProd = someList.toString().lastIndexOf(prodname); //returns -1
How could I use the data[0] as the parameter in lastIndexOf without using the ""?
EDIT:
Example:
data[0] = "Lorem Ipsum"
String someList = "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. "
int posProd = someList.toString().lastIndexOf(data[0]); //returns -1
But When I test it to:
int posProd = someList.toString().lastIndexOf("Lorem Ipsum"); //returns the position
EDIT 2:
List<HtmlDivision> productDesc = page.getByXPath("//div[@class='col-md-6 md-margin-bottom-10']//following-sibling::div");
String productDescList = "";
for(HtmlDivision prodName:productDesc){
productDescList = productDescList.trim()+prodName.asText().trim();
}
System.out.println("productDescList: " +productDescList);
String prodname = String.valueOf(data[0]);
System.out.println("prodname: " +prodname.trim());
int posProd = productDescList.toString().lastIndexOf(prodname);
String cleanDesc = productDescList.substring(posProd, productDescList.length()-5);
System.out.println("cleanDesc: " +cleanDesc);