Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. gettablevalueshopcart("//div[@id='Catalog']//tr",2,"Large Angelfish",0,"EST-1");
  2.  
  3. public class petstore {
  4.  
  5. public static void gettablevalueshopcart(String xPath1,int descriptionid, String expectvalue1, int itemid, String expectedvalue2) {
  6.  
  7. try
  8. {
  9. //String xPath1 = "//div[@id='Catalog']//tr";
  10. List<WebElement> shoppingtableList = driver.findElements(By.xpath(xPath1));
  11. System.out.println("Item IDttProduct IDttDescriptionttInstockttList PricetTotalcostttButton");
  12. System.out.println("---------------------------------------------------------------------------------------------------------------------------------");
  13. for(int i=1;i<shoppingtableList.size();i++) {
  14. List<WebElement> listData = driver.findElements(By.xpath(xPath1+"["+(i+1)+"]/td"));
  15. for(int j=0;j<listData.size();j++) {
  16.  
  17. System.out.print(listData.get(j).getText()+"tt");
  18. }
  19. System.out.println();
  20. }
  21. // description is in the 3rd(2nd index) column so we can fetch that with the index number 2.
  22. for(int i=1;i<shoppingtableList.size();i++) {
  23. List<WebElement> listData = driver.findElements(By.xpath(xPath1+"["+(i+1)+"]/td"));
  24.  
  25. if(listData.get(descriptionid).getText().trim().equals(expectvalue1))
  26. {
  27. System.out.println("Description for Item ID is "+listData.get(descriptionid).getText());
  28. }
  29.  
  30. if(listData.get(itemid).getText().trim().equals(expectedvalue2)) {
  31. System.out.println("Item ID is "+listData.get(itemid).getText());
  32. break;
  33. }
  34. }
  35.  
  36. }
  37.  
  38. catch(Exception e)
  39. {
  40. System.out.println(e.getMessage());
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement