I have an arbitrary number of tiles that have a unique class name. One of them has a unique title so I'm trying to grab that one specifically. Once I've done that, I want a reference to child element rather deep in its structure.
Does the "tile." part of tile.findElement() do anything for me here? I want to be specifically using an xpath relative to tile.
public WebElement getArticleTileByTitle(String title){
By xpath = By.xpath(".//div[contains(., '" + title + "') or @title='" + title + "']");
List<WebElement> tiles = findPresentElements(By.className("articleTile"));
for(WebElement tile : tiles){
if(isElementPresent(tile, xpath))
return tile;
}
return null;
}
public boolean articleTileImageIsVisible(WebElement tile){
WebElement background = tile.findElement(By.xpath("/*[2]/*[2]/*[1]/*[3]")); //This throws NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/*[2]/*[2]/*[1]/*[3]"}
//figure out stuff about background
}
I know that background is of type img so I've tried
tile.findElement(By.xpath("./img/*[2]/*[2]/*[1]/*[3]"));
tile.findElement(By.xpath("./*/*[2]/*[2]/*[1]/*[3]"));
tile.findElement(By.xpath(".//*/*[2]/*[2]/*[1]/*[3]"));
tile.findElement(By.xpath("./*/*[2]/*[2]/*[1]/*[3]"));
Never the less, I keep getting variations on NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/[2]/[2]/[1]/[3]"} and That's not a valid xpath.
This question is very similar to Selenium 2 - Can findElement(By.xpath) be scoped to a particular element? but people seem to have either misinterpreted it or my use case is different.