import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//Getting count of Different Web Element displayed
public class WebDriverElementCount {
public static WebDriver oBrowser;
public static String sUrl="http://in.yahoo.com";
public static void main(String[] args)
{
boolean bIsBrowserOpened;
bIsBrowserOpened=OpenBrowser();
if(bIsBrowserOpened)
{
Display_Element_Count();
CloseBrowser();
}
}
public static boolean OpenBrowser()
{
try
{
oBrowser=new FirefoxDriver();
oBrowser.get(sUrl);
try
{
Thread.sleep(5000L);
}
catch(Exception e)
{
e.printStackTrace();
}
return true;
}
catch(Exception e)
{
System.err.println(e.getMessage());
return false;
}
}
public static void Display_Element_Count()
{
Get_Element_Count("Link","//a");
Get_Element_Count("Image","//img");
Get_Element_Count("TextBox","//input[@type='text']");
Get_Element_Count("Form Submit Button","//input[@type='submit' or @type='clear']");
Get_Element_Count("HTML 4/5 button","//button");
Get_Element_Count("Radio Button","//input[@type='radio']");
Get_Element_Count("CheckBox","//input[@type='checkbox']");
Get_Element_Count("List Box","//select");
Get_Element_Count("Activex Button","//object");
Get_Element_Count("Text Area","//textarea");
}
public static void Get_Element_Count( String sElementName,String sXpath_of_Element)
{
int iCount;
if(!sXpath_of_Element.isEmpty())
{
iCount=oBrowser.findElements(By.xpath(sXpath_of_Element)).size();
System.out.printf("\n No of (%s) Element= %d" ,
sElementName,iCount);
}
}
public static void CloseBrowser()
{
oBrowser.close();
}
}
import org.openqa.selenium.firefox.FirefoxDriver;
//Getting count of Different Web Element displayed
public class WebDriverElementCount {
public static WebDriver oBrowser;
public static String sUrl="http://in.yahoo.com";
public static void main(String[] args)
{
boolean bIsBrowserOpened;
bIsBrowserOpened=OpenBrowser();
if(bIsBrowserOpened)
{
Display_Element_Count();
CloseBrowser();
}
}
public static boolean OpenBrowser()
{
try
{
oBrowser=new FirefoxDriver();
oBrowser.get(sUrl);
try
{
Thread.sleep(5000L);
}
catch(Exception e)
{
e.printStackTrace();
}
return true;
}
catch(Exception e)
{
System.err.println(e.getMessage());
return false;
}
}
public static void Display_Element_Count()
{
Get_Element_Count("Link","//a");
Get_Element_Count("Image","//img");
Get_Element_Count("TextBox","//input[@type='text']");
Get_Element_Count("Form Submit Button","//input[@type='submit' or @type='clear']");
Get_Element_Count("HTML 4/5 button","//button");
Get_Element_Count("Radio Button","//input[@type='radio']");
Get_Element_Count("CheckBox","//input[@type='checkbox']");
Get_Element_Count("List Box","//select");
Get_Element_Count("Activex Button","//object");
Get_Element_Count("Text Area","//textarea");
}
public static void Get_Element_Count( String sElementName,String sXpath_of_Element)
{
int iCount;
if(!sXpath_of_Element.isEmpty())
{
iCount=oBrowser.findElements(By.xpath(sXpath_of_Element)).size();
System.out.printf("\n No of (%s) Element= %d" ,
sElementName,iCount);
}
}
public static void CloseBrowser()
{
oBrowser.close();
}
}
DragDrop doesn't work with selenium IDE?
ReplyDeleteIt was very nice article and it is very useful to Selenium learners.We also provide Cub training software online training.
ReplyDeleteIt was very nice article on getting the count.
ReplyDeleteI also found an other website which is very helpful with many examples and it is very useful to Selenium beginners
Selenium Wedriver Tutorials
ReplyDeleteValuable information thanks for sharing HP ALM Online Training BY Cheyat Technologies
ReplyDeleteAdvanced Selenium Framework Training in Chennai by Vishwa
Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.
I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
selenium training in chennai
Thanks for sharing great information in your blog.
ReplyDeleteSelenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS
http://thecreatingexperts.com/selenium-training-in-chennai/
contact-8122241286