Appium findElement used twice in one row not working
They are not the same.
appDriver.findElement(By.xpath("//UIATableCell[2]")).findElement(By.xpath("//UIAStaticText[4]"));
Here, you are searching for //UIAStaticText[4]
anywhere, at any level in the entire DOM tree:
When using xpath be aware that webdriver follows standard conventions: a search prefixed with "//" will search the entire document, not just the children of this current node. Use ".//" to limit your search to the children of this WebElement.
While //UIATableCell[2]/UIAStaticText[4]
would search among the direct children of //UIATableCell[2]
only.
I would do it like so instead:
By locator = new ByChained(By.xpath("//UIATableCell[2]"),By.xpath(".//UIAStaticText[4]")); WebElement modularElement = appDriver.findElement(locator);
Or perhaps this:
public WebElement getCellTextElement(int cell, String varText) { By locator = new ByChained(By.xpath("//UIATableCell[" + cell + "]"), By.xpath(".//UIAStaticText[contains(text(),'" + varText + "')]")); WebElement modularElement = appDriver.findElement(locator); return modularElement;}