Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.  
  5.         ChromeDriver driver = new ChromeDriver();
  6.         String url = "https://www.czc.cz/macbooky/produkty";
  7.         driver.get(url);
  8.  
  9.         List<WebElement> macs = null;
  10.  
  11.         try {
  12.             macs = driver.findElementsByClassName("per-item medal tracked");
  13.         } catch (Exception e) {
  14.             System.out.println(e.getMessage());
  15.         }
  16.         System.out.println(macs.size());
  17.         WebElement firstMac = macs.get(0);
  18.  
  19.         String firstMacUrl = firstMac.getAttribute("href");
  20.         System.out.println(firstMacUrl);
  21.  
  22.         driver.get(firstMacUrl);
  23.  
  24.         try {
  25.             WebElement product = driver.findElementByPartialLinkText("Nokia 3310, Dual Sim, šedá");
  26.             if (product.isDisplayed()) {
  27.                 System.out.println("Product is in the basket.");
  28.             } else {
  29.                 System.out.println("Product not found in the basket");
  30.             }
  31.  
  32.         } catch (Exception e) {
  33.             e.printStackTrace();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement