Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- public class testexamplevirtuemart {
- public static void main(String[] args) throws InterruptedException {
- WebDriver myTestDriver = new FirefoxDriver();
- myTestDriver.manage().window().maximize();
- myTestDriver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
- myTestDriver.get("http://tinyurl.com/brnygh4");
- // fill List with all total no of products link
- List<WebElement> AllMobilePhonesLinks = myTestDriver.findElements(By.xpath("//div[@class='spacer']/h3/a"));
- System.out.println("Total No of products ------"+ AllMobilePhonesLinks.size());
- //print all mobile names on console
- for(int i=0;i<AllMobilePhonesLinks.size();i++){
- System.out.println(AllMobilePhonesLinks.get(i).getText());
- }
- // Fill list with all Product details links for each phone
- List<WebElement> AllMobilePhonesButtons = myTestDriver.findElements(By.xpath("//div[@class='product-link']/a[@class='btn btn-small']"));
- System.out.println(AllMobilePhonesButtons.size());
- // Loop through all product names to get the desired product
- for(int i=0;i<AllMobilePhonesButtons.size();i++){
- // Click on Product when name of the product is matched with "i9000 Galaxy S"
- if (AllMobilePhonesLinks.get(i).getText().equals("i9000 Galaxy S") ) {
- AllMobilePhonesButtons.get(i).click();
- break;
- }
- Thread.sleep(50000L);
- myTestDriver.quit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement