Saturday, 18 February 2012

Extract all links from a webpage using webdriver for selenium automation testing


import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class dadabhagwan_LearnSeleniumWithJasmine {

public static void main(String[] args) throws InterruptedException {

WebDriver myDriver = new FirefoxDriver();
myDriver.get("http://satsang.dadabhagwan.org/");

/*Extract all links from the webpage using selenium webdriver*/
List all_links_webpage = myDriver.findElements(By.tagName("a"));

/*Print total no of links on the webpage*/
System.out.println("Print total no of links on the webpage---------------------------------------------");
System.out.println(all_links_webpage.size());

/*Print text of all links*/
System.out.println("Print text of all links------------------------------------------------------------");
for(int i=0;i
System.out.println(all_links_webpage.get(i).getText());
}

/*Print Links*/
System.out.println("Print Links------------------------------------------------------------------------");
for(int i=0;i
System.out.println(all_links_webpage.get(i).getAttribute("href"));
}



/*Extract all links from the part of the webpage using selenium webdriver*/
System.out.println("Extract all links from the part of the webpage using selenium webdriver-----------------------------");
List myList = myDriver.findElement(By.xpath("//*[@id='Flot']")).findElements(By.tagName("a"));

System.out.println("total no links on specific part of webpage---------------------------------------------------");
System.out.println(myList.size());

System.out.println("Text of the link for specific part of webpage--------------------------------------------------");
for(int i =0; i< myList.size();i++){
System.out.println(myList.get(i).getText());

}

}

}

Extract all links from specific part of the webpage using webdriver for selenium automation testing


importjava.util.List;

importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.firefox.FirefoxDriver;


public classdadabhagwan_LearnSeleniumWithJasmine {

       public static voidmain(String[] args) throws InterruptedException {
             
              WebDriver myDriver = newFirefoxDriver();
              myDriver.get("http://satsang.dadabhagwan.org/");
             
              /*Extract all links from the webpage using selenium webdriver*/
              Listall_links_webpage = myDriver.findElements(By.tagName("a"));
             
              /*Print total no of links on the webpage*/
              System.out.println("Print total no of links on the webpage---------------------------------------------");
              System.out.println(all_links_webpage.size());
             
              /*Print text of all links*/
              System.out.println("Print text of all links------------------------------------------------------------");
              for(int i=0;i
                     System.out.println(all_links_webpage.get(i).getText());
              }
             
              /*Print Links*/
              System.out.println("Print Links------------------------------------------------------------------------");
              for(inti=0;i
                     System.out.println(all_links_webpage.get(i).getAttribute("href"));
              }
             
             
             
              /*Extract all links from the part of the webpage using selenium webdriver*/
              System.out.println("Extract all links from the part of the webpage using selenium webdriver-----------------------------");
              List< WebElement > myList = myDriver.findElement(By.xpath("//*[@id='Flot']")).findElements(By.tagName("a"));
             
              System.out.println("total no links on specific part of webpage---------------------------------------------------");
              System.out.println(myList.size());
             
              System.out.println("Text of the link for specific part of webpage--------------------------------------------------");
              for(int i =0; i< myList.size();i++){
                     System.out.println(myList.get(i).getText());

              }
             

       }

}

Working with CheckBoxes using webdriver for selenium automation testing


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class dadabhagwan_LearnSeleniumWithJasmine {

public static void main(String[] args) throws InterruptedException {

WebDriver myDriver = new FirefoxDriver();
myDriver.get("http://egroup.dadabhagwan.org/Register.aspx");

myDriver.findElement(By.xpath("//*[@id='ctl00_cpMaster_chkNews_0']")).click();
System.out.println(myDriver.findElement(By.xpath("//*[@id='ctl00_cpMaster_chkNews_1']")).getAttribute("checked"));
System.out.println(myDriver.findElement(By.xpath("//*[@id='ctl00_cpMaster_chkNews_0']")).getAttribute("checked"));

String xpath_SubscriptionInformation_front = "//*[@id='ctl00_cpMaster_chkNews_";
String xpath_SubscriptionInformation_rear = "']";

for(int i=0;i<=9;i++){
System.out.print(myDriver.findElement(By.xpath(xpath_SubscriptionInformation_front+i+xpath_SubscriptionInformation_rear)).getAttribute("name")+"---------");
System.out.println(myDriver.findElement(By.xpath(xpath_SubscriptionInformation_front+i+xpath_SubscriptionInformation_rear)).getAttribute("checked"));
myDriver.findElement(By.xpath(xpath_SubscriptionInformation_front+i+xpath_SubscriptionInformation_rear)).click();
System.out.print(myDriver.findElement(By.xpath(xpath_SubscriptionInformation_front+i+xpath_SubscriptionInformation_rear)).getAttribute("name")+"---------");
System.out.println(myDriver.findElement(By.xpath(xpath_SubscriptionInformation_front+i+xpath_SubscriptionInformation_rear)).getAttribute("checked"));
}

}

}

working with radio buttons for selenium automation testing


import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class dadabhagwan_LearnSeleniumWithJasmine {

public static void main(String[] args) throws InterruptedException {

WebDriver myDriver = new FirefoxDriver();
myDriver.get("http://egroup.dadabhagwan.org/Register.aspx");


// radio button group of "Gnan Taken"
List radio_Gnan_Taken = myDriver.findElements(By.name("ctl00$cpMaster$grpGyan"));

for(int i=0;i
System.out.print(radio_Gnan_Taken.get(i).getAttribute("Value")+"*************");
System.out.println(radio_Gnan_Taken.get(i).getAttribute("checked"));
}

radio_Gnan_Taken.get(0).click();

for(int i=0;i
System.out.print(radio_Gnan_Taken.get(i).getAttribute("Value")+"*************");
System.out.println(radio_Gnan_Taken.get(i).getAttribute("checked"));
}

// radio button group of "Dadavani Magazine Member"
radio_Gnan_Taken = myDriver.findElements(By.name("ctl00$cpMaster$grpDadawani"));

for(int i=0;i
System.out.print(radio_Gnan_Taken.get(i).getAttribute("Value")+"*************");
System.out.println(radio_Gnan_Taken.get(i).getAttribute("checked"));
}

radio_Gnan_Taken.get(0).click();

for(int i=0;i
System.out.print(radio_Gnan_Taken.get(i).getAttribute("Value")+"*************");
System.out.println(radio_Gnan_Taken.get(i).getAttribute("checked"));
}


// radio button group of "Preferred format for email"
radio_Gnan_Taken = myDriver.findElements(By.name("ctl00$cpMaster$grpEformat"));

for(int i=0; i
System.out.print(radio_Gnan_Taken.get(i).getAttribute("Value")+"*************");
System.out.println(radio_Gnan_Taken.get(i).getAttribute("checked"));
}


radio_Gnan_Taken.get(0).click();

for(int i=0;i
System.out.print(radio_Gnan_Taken.get(i).getAttribute("Value")+"*************");
System.out.println(radio_Gnan_Taken.get(i).getAttribute("checked"));
}


}

}

Friday, 17 February 2012

How to select Dropdown values using Selenium(Webdriver) for selenium automation testing


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class dadabhagwan_LearnSeleniumWithJasmine {

public static void main(String[] args) throws InterruptedException {

WebDriver myDriver = new FirefoxDriver();
myDriver.get("http://www.artofliving.org");


myDriver.findElement(By.id("div-local-center-title")).click();
myDriver.findElement(By.id("edit-state-selector")).sendKeys("Chandigarh");



}

}