Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gettablevalueshopcart("//div[@id='Catalog']//tr",2,"Large Angelfish",0,"EST-1");
- public class petstore {
- public static void gettablevalueshopcart(String xPath1,int descriptionid, String expectvalue1, int itemid, String expectedvalue2) {
- try
- {
- //String xPath1 = "//div[@id='Catalog']//tr";
- List<WebElement> shoppingtableList = driver.findElements(By.xpath(xPath1));
- System.out.println("Item IDttProduct IDttDescriptionttInstockttList PricetTotalcostttButton");
- System.out.println("---------------------------------------------------------------------------------------------------------------------------------");
- for(int i=1;i<shoppingtableList.size();i++) {
- List<WebElement> listData = driver.findElements(By.xpath(xPath1+"["+(i+1)+"]/td"));
- for(int j=0;j<listData.size();j++) {
- System.out.print(listData.get(j).getText()+"tt");
- }
- System.out.println();
- }
- // description is in the 3rd(2nd index) column so we can fetch that with the index number 2.
- for(int i=1;i<shoppingtableList.size();i++) {
- List<WebElement> listData = driver.findElements(By.xpath(xPath1+"["+(i+1)+"]/td"));
- if(listData.get(descriptionid).getText().trim().equals(expectvalue1))
- {
- System.out.println("Description for Item ID is "+listData.get(descriptionid).getText());
- }
- if(listData.get(itemid).getText().trim().equals(expectedvalue2)) {
- System.out.println("Item ID is "+listData.get(itemid).getText());
- break;
- }
- }
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement