-1

IE browser does not support Action class. Is it possible to multi select the items in a table using any other way? If any, please share.

Please find the sample structure of the table to select the values. Now i want to select the Text1, Text3 & Text5 values. Am able to select using Action class in Chrome, FF browser using selenium 2.52.0 but not able to select in IE/Safari.

<table>
<tr><td><div><span>Text1<span/><div/><td/><tr/>
<tr><td><div><span>Text2<span/><div/><td/><tr/>
<tr><td><div><span>Text3<span/><div/><td/><tr/>
<tr><td><div><span>Text4<span/><div/><td/><tr/>
<tr><td><div><span>Text5<span/><div/><td/><tr/>
<table>

Function used to click:

String[] items = itemName.split("\n");// Items to be clicked
Actions builder = new Actions(driver);
for(int counter = 0; counter < items.length; counter++) 
{
    this.listingRows = this.listing.findElement(By.cssSelector("table[id='mainTable']"));
    List<WebElement> element = listingRows.findElements(By.cssSelector("tr[class='sample']>td>div>span")); //Getting the row elements
    int itemCnt =  element.size();
    String item;
    for(int i =0;i<itemCnt;i++){
    item = element.get(i).getText();            
    if(item.equalsIgnoreCase(items[counter])){
    builder.keyDown(Keys.CONTROL).click(element.get(i)).keyUp(Keys.CONTROL);
    builder.build().perform();
     }
     }
    }

1 Answers1

-1

First, you can inspect the table

WebElement data1=d.findElement(By.xpath(""));

then, select row by row

List<WebElement> tableRows = data1.findElements(By.tagName("tr"));

using loop you can repeat through out the columns

for (int i=0; i<rowSize; i++) 
    {
        WebElement webRow = tableRows.get(i);
        //Get all cell values in each row
        List<WebElement> allCells = webRow.findElements(By.tagName("td"));
        //System.out.println(allCells.size());
        if(allCells.size() > 1)
        {
            row = st1.createRow(i);
            for (int j=0; j<allCells.size(); j++)
            {
                WebElement webCell = allCells.get(j);
                String text = webCell.getText();
                if(text.length()>3)
                {
                    cell = row.createCell(j);
                    cell.setCellValue(webCell.getText());
                }
            }
        }

try once..!!

Ravi Potnuru
  • 191
  • 4
  • 13