I have a search result page which contains many product items which are produced as a search result. I can get the list of the product items. But there are product details like price, discount, shipping price which are inside these webelements as child elements. How can I use page object factory model to get the values of these child elements automatically by using the @FindBy annotation.
At the moment I do not know how so I am getting them explicitly by providing the context of the parent WebElement in the findElement(By) function explicitly rather than the automatic mechanism of POF. Question is how to make the context as a WebElement rather than a driver object for a PageObject class. I have not been able to find any understandable web article explaining how to do it. Could someone explain a SIMPLE way to do it hopefully with an example.... I would be really grateful. Below is the code to explain the Test Class and the class to represent the product.
public class TestProducts {
.....
//I can get the list of products from a
List<WebElement> we_prod_box_list = driver.findElements(By.xpath("//div[@id='content']/descendant::div[starts-with(@class,'product_box_container')]"));
.....
}
public class ProductItem {
private WebDriver driver = null;
private Actions action = null;
private WebElement we_prod_box = null;
public String we_prod_box_title = "";
public WebElement we_pt = null;
public String slideImgTitle = "";
public String oldPrice = "";
public String oldPriceTitle = "";
public String subPrice = "";
public WebElement we_purch_disc = null;
private WebDriverWait wait = null;
public String shippingText = "";
public String shippingCost = "";
public String discPrice = "";
.....
we_pt = we_prod_box.findElement(By.xpath(".//div[contains(@class, 'subcategor_price_tag')]"));
slideImgTitle = we_pt.findElement(By.xpath(".//div[contains(@class, 'subcategor_slideimgtitle')]")).getText();
oldPrice = we_prod_box.findElement(By.xpath(".//div[contains(@class, 'oldprice')]")).getText();
oldPriceTitle = we_prod_box.findElement(By.xpath(".//div[contains(@class, 'oldprice')]")).getAttribute("title");
subPrice = we_prod_box.findElement(By.xpath(".//span[contains(@class, 'sub-price')]")).getText();
......
}