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]"));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With