import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.support.ui.Select;
// - Selecting Existing list of values from ListBox
// and check which value is selected
public class WebDriver19 {
/**
* @param args
*/
public static WebDriver oBrowser;
public static String sUrl = "http://www.goibibo.com";
public static void main(String[] args)
{
boolean bIsBrowserOpened;
bIsBrowserOpened = OpenBrowser();
if (bIsBrowserOpened)
{
Set_ListBox_Item_Method3();
//Set_ListBox_Item_Method2_Valid();
//Set_ListBox_Item_Method2_InValid();
CloseBrowser();
}
}
public static boolean OpenBrowser()
{
try
{
oBrowser = new FirefoxDriver();
oBrowser.get(sUrl);
try
{
Thread.sleep(5000L);
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch (Exception e)
{
System.err.println(e.getMessage());
return false;
}
return true;
}
public static void CloseBrowser()
{
oBrowser.close();
}
public static void Set_ListBox_Item_Method1()
{
WebElement oListBox;
oListBox = oBrowser.findElement(By.id("gi_source"));
oListBox.sendKeys("Hyderabad");
}
//For throwing not found exception
public static void Set_ListBox_Item_Method2_Valid()
{
WebElement oListBox;
oListBox = oBrowser.findElement(By.id("gi_source"));
//oListBox.sendKeys("Hyderabad");
try
{
oListBox.findElement(By.xpath("//option[@value='HYD']")).click();
}
catch(NoSuchElementException e)
{
System.out.println("Specified Item Not Found");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void Set_ListBox_Item_Method2_InValid()
{
WebElement oListBox;
oListBox = oBrowser.findElement(By.id("gi_source"));
//oListBox.sendKeys("Hyderabad");
try
{
oListBox.findElement(By.xpath("//option[@value='HYD123']")).click();
}
catch(NoSuchElementException e)
{
System.out.println("Specified Item Not Found");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void Set_ListBox_Item_Method3()
{ //using select class
WebElement oListBox;
Select ListSelect;
oListBox = oBrowser.findElement(By.id("gi_source"));
ListSelect=new Select(oListBox);
ListSelect.selectByValue("HYD");
System.out.println("Selected:= "+ListSelect.getAllSelectedOptions().get(0).getText());
ListSelect.selectByVisibleText("Pune");
System.out.println("Selected:= "+ListSelect.getAllSelectedOptions().get(0).getText());
}
}
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.support.ui.Select;
// - Selecting Existing list of values from ListBox
// and check which value is selected
public class WebDriver19 {
/**
* @param args
*/
public static WebDriver oBrowser;
public static String sUrl = "http://www.goibibo.com";
public static void main(String[] args)
{
boolean bIsBrowserOpened;
bIsBrowserOpened = OpenBrowser();
if (bIsBrowserOpened)
{
Set_ListBox_Item_Method3();
//Set_ListBox_Item_Method2_Valid();
//Set_ListBox_Item_Method2_InValid();
CloseBrowser();
}
}
public static boolean OpenBrowser()
{
try
{
oBrowser = new FirefoxDriver();
oBrowser.get(sUrl);
try
{
Thread.sleep(5000L);
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch (Exception e)
{
System.err.println(e.getMessage());
return false;
}
return true;
}
public static void CloseBrowser()
{
oBrowser.close();
}
public static void Set_ListBox_Item_Method1()
{
WebElement oListBox;
oListBox = oBrowser.findElement(By.id("gi_source"));
oListBox.sendKeys("Hyderabad");
}
//For throwing not found exception
public static void Set_ListBox_Item_Method2_Valid()
{
WebElement oListBox;
oListBox = oBrowser.findElement(By.id("gi_source"));
//oListBox.sendKeys("Hyderabad");
try
{
oListBox.findElement(By.xpath("//option[@value='HYD']")).click();
}
catch(NoSuchElementException e)
{
System.out.println("Specified Item Not Found");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void Set_ListBox_Item_Method2_InValid()
{
WebElement oListBox;
oListBox = oBrowser.findElement(By.id("gi_source"));
//oListBox.sendKeys("Hyderabad");
try
{
oListBox.findElement(By.xpath("//option[@value='HYD123']")).click();
}
catch(NoSuchElementException e)
{
System.out.println("Specified Item Not Found");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void Set_ListBox_Item_Method3()
{ //using select class
WebElement oListBox;
Select ListSelect;
oListBox = oBrowser.findElement(By.id("gi_source"));
ListSelect=new Select(oListBox);
ListSelect.selectByValue("HYD");
System.out.println("Selected:= "+ListSelect.getAllSelectedOptions().get(0).getText());
ListSelect.selectByVisibleText("Pune");
System.out.println("Selected:= "+ListSelect.getAllSelectedOptions().get(0).getText());
}
}
nice programming on Selenium. Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. For more details.
ReplyDeleteCheck this site tekslate for indepth tutorials/selenium-tutorials/
Go here if you’re looking for information on tutorials/selenium-tutorials/
nice programming on Selenium. Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. For more details.
ReplyDeleteCheck this site tekslate for indepth tutorials/selenium-tutorials/
Go here if you’re looking for information on tutorials/selenium-tutorials/
Great post!
ReplyDeleteThanks for sharing this information.post more articles like this...........
We provide Quality Trainings for all courses by who is having professional experience & hands on real time experts.
Selenium Online Training
Thanks you for the awesome information in your blog on Selenium training in Chennai
ReplyDeleteThanks you for the awesome information in your blog on Selenium training in Chennai
ReplyDelete
ReplyDeleteValuable information thanks for sharing HP ALM Online Training BY Cheyat Technologies
Thank you! Learn Software Testing Tools Training by Best Training Institute QEdge Technologies.
ReplyDeleteSelenium Training in Hyderabad
This is very informative blog and article thank you for sharing with us keep posting more information about salesforce trainingselenium training, selenium online training, selenium course,learn selenium course
ReplyDelete
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
Thanks for sharing great information in your blog.
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
spoken english classes in chennai | Communication training