Monday, March 18, 2013

How to choose Ext JS Combo values using Selenium WebDriver

When we see Ext JS Combo box, it looks like a ordinary combo box and when we try

Select oSel=
new Select(oCategoryItems);
List<WebElement> oListItems=oSel.getOptions();

It throws an error message saying,
Element should have been "select" but was "input"

The reason being Ext JS combo box are not just combo boxes, they combination of controls like,
<Input> and <Image> or <em>
<input> and <Select>

You can see the sample combo box object in Naukri.com website, which is attached


So inorder to select these items, first we need to click on the Input object and then select the value.

Following is the code for printing out all the values, you can use whatever function you want after clicking the object.


 
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;
import
org.openqa.selenium.support.ui.Select;
 
public
class PrintListBoxValues
{
public static void main(String[] args)
{
WebDriver driver=
new FirefoxDriver();
driver.get(
"http://www.naukri.com/");
WebElement oCategory=driver.findElement(By.id(
"farea"));
oCategory.click();
WebElement oCategoryItems=driver.findElement(By.id(
"fareaSL"));
Select oSel=
new Select(oCategoryItems);
List<WebElement> oListItems=oSel.getOptions();
for(int i=1;i<=oListItems.size()-1;i++)
{
System.
out.println(oListItems.get(i).getText());
}
}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.