Quality Testing

Quality is delighting customers

Hi friends.

Please give me solution for this scenario:-

Scenario:-

1. Click on ebay.com

2. select books in category.

3. Display all categories in the console output.

thanks

kayan.

Views: 173

Reply to This

Replies to This Discussion

WebElement dd=driver.findElement(By.xpath("//select[@title='Select a category for search']"));

Select s=new Select(dd);// Here i am using select class and creating an object of select class and passing webelement as an argument. Since this is a Drop Down Box we need to use select Class

List<WebElements> alloptions= s.getOptions();// GetOptions will get all the List of Options

for(int i=0; i<alloptions.size(); i++){

  WebElement opt =alloptions.get(i);// Using For loop I am getting  one by one Option

System.out.println("All Options Text"+ opt.getText());//Here i am finding the text of each option

}

I am not sure what is happening with E Bay site. But i tried the same option for flip cart and it works fine. Please find the entire code below.

package com.krishna;

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;
import org.openqa.selenium.support.ui.Select;

public class SelectDropDown {

/**
* @param args
*/
public static void main(String[] args)throws InterruptedException {
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://www.flipkart.com/");
WebElement dd=driver.findElement(By.id("fk-search-select"));
Select s=new Select(dd);
List<WebElement> alloptions= s.getOptions();
System.out.println(alloptions.size());
for(int i=0; i<alloptions.size(); i++){
WebElement opt =alloptions.get(i);
System.out.println(opt.getText());

}
}

}

Krishna, 

Thanks dude it will work in flipkart site

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service