SeleniumETrainR

Example for selenium webdriver - with PrestaShop's free ecom

Dec 19th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.concurrent.TimeUnit;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.firefox.FirefoxDriver;
  6.  
  7.  
  8. public class testPrestashopExample {
  9.  
  10.      
  11.     public static void main(String[] args) {
  12.         WebDriver myTestDriver = new FirefoxDriver();
  13.         myTestDriver.manage().window().maximize();
  14.        
  15.         myTestDriver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
  16.         myTestDriver.get("http://demo-store.prestashop.com");
  17.        
  18.        
  19.         myTestDriver.findElement(By.xpath("//*[@id='header']/div[2]/ul/li[3]/a")).click();
  20.        
  21.          
  22.        
  23.          
  24.     try {
  25.         for (int i = 1; i < 9; i++) {
  26.             if(myTestDriver.findElement(By.xpath("//*[@id='product_list']/li["+i+"]/div[2]/h3/a")).getText().equals("iPhone 4S")){
  27.                
  28.                 myTestDriver.findElement(By.xpath("//*[@id='product_list']/li["+i+"]/div[3]/a")).click();
  29.                
  30.             }
  31.         }
  32.  
  33.     } catch (Exception e) {
  34.          
  35.     }  
  36.        
  37.        
  38.     }
  39.  
  40.  
  41.     }
Add Comment
Please, Sign In to add comment