質問

I have randomly generated table. Currently I am able to get table cell data using selenium.getTable(XPath) but I am not able change that value. My functions are :

    public static String getGridCellValue(Selenium selenium, String strGridId, int nRowIndex, int nCellIndex)
{
    String strXPath = "//div[@id='"+strGridId+"']/table/tbody/tr[2]/td/div/div/table."+(nRowIndex + 1)+"."+(nCellIndex);
    return selenium.getTable(strXPath);
}

But I am not able to write set method as :

    public static void setGridCellValue(Selenium selenium, String strGridId, int nRowIndex, int nCellIndex, String strValue)
{

    String strXPath = "//div[@id='"+strGridId+"']/table/tbody/tr[2]/td/div/div/table."+(nRowIndex + 1)+"."+(nCellIndex);
    selenium.type(strXPath, strValue);
}

It is saying

com.thoughtworks.selenium.SeleniumException: Element //div[@id='gridPShipsRel']/table/tbody/tr[2]/td/div/div/table.1.5 not found

Does anyone know how to set table value in selenium ?

役に立ちましたか?

解決

Not sure how strXPath = "//div[@id='"+strGridId+"']/table/tbody/tr[2]/td/div/div/table."+(nRowIndex + 1)+"."+(nCellIndex) will retrieve cell. Add some HTML or

You can following method, this will update the cell value

public String updateCell(By identifier, int romNumber, int columnNumber, String value) 
{
   WebElement table = driver.findElement(identifier);
   List<WebElement> rows = table.findElements(By.xpath("tbody/tr"));
   List<WebElement> cells = rows.get(romNumber).findElements(By.tagName("td"));
   WebElement desiredCell = cells.get(columnNumber);
   desiredCell.setText(value);
}

EDIT : By Looking at your imports com.thoughtworks.selenium. I can say that you are using Selenium RC. My solution is webdriver based

他のヒント

For your set method try to give xpath this way:

strXpath = "//div[@id='"+strGridId+"']/table/tbody/tr[2]/td/div/div/table/tbody/tr["+(nRowIndex + 1)+"]/td[" +(nCellIndex)+"]"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top