Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appium findElement used twice in one row not working

I am trying to find an element by its full path (wholeElement) and by first finding the higher level element and then finding the lower level element within that element (modularElement). Here is my code:

    WebElement modularElement = appDriver.findElement(By.xpath("//UIATableCell[2]")).findElement(By.xpath("//UIAStaticText[4]"));
    WebElement wholeElement = appDriver.findElement(By.xpath("//UIATableCell[2]/UIAStaticText[4]"));

    Logger.LogMessage("modularElement attribute1: " + modularElement.getLocation(), Priority.High);
    Logger.LogMessage("wholeElement attribute1: " + wholeElement.getLocation(), Priority.High);

The really strange issue I am experiencing is the two elements (modular and whole) are different elements and not the same one (shown by the different locations printed in the code above). Can anyone explain why this is the case?

Thanks.

UPDATE:

I have also tried using .// but that is providing the same issue still:

    WebElement modularElement = appDriver.findElement(By.xpath("//UIATableCell[2]")).findElement(By.xpath(".//UIAStaticText[4]"));
like image 335
Charlie Seligman Avatar asked Jun 05 '15 10:06

Charlie Seligman


1 Answers

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.

like image 189
alecxe Avatar answered Nov 15 '22 16:11

alecxe