samedi 16 décembre 2017

Select dynamic option in a table through selenium

I have a dynamic table to select an option while logging in to the site. The displayed options is sorted Alphabetically based on the subscriptions of the User. My Selenium code is like below works perfectly, till i test the subscribe option for a logged in user.

package mypackage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class MyClass {

    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        //To wait until the element get visible or invisible.
        WebDriverWait wait = new WebDriverWait(driver, 25);
        driver.get("http://ift.tt/2AF9MP6");  
        //For wait until the element get visible.
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("gvItemListing_grdSelect_0")));
        //Select Option 3 displayed and submit
        driver.findElement(By.id("gvItemListing_grdSelect_3")).click();
        driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
    }

}

I have created a sample page http://ift.tt/2AF9MP6 which will rotate the options randomly. I want to select an option (say Option 3) from the table. How do I will be able to find in which Row my required Option is displayed? I will then be able to select the option by selecting the option "gvItemListing_grdSelect_"

Aucun commentaire:

Enregistrer un commentaire