A generic answer might be a little tricky. Generally speaking, if you
are trying to find an element you have to do the following:
- find the iframe
- switch to the iframe
- find the element
If the element is in an iframe, inside an iframe, inside an iframe,
etc. this is where a generic solution gets tricky. If you are looking
for a solution to a specific application then the algorithm is:
- find the iframe
- get the iframe Location
- get the X value
- get the Y value
- switch to the iframe
- find the element
- get the element Location
- add the X value to the above X value
- add the Y value to the above Y value
The indented lines are additions to the original algorithm. In actual
code:
public Point getAbsoluteLocation(By iframeLocator, By elementLocator)
{
Point p;
WebElement iframe = driver.findElement(iframeLocator);
Point iframeLoc = iframe.getLocation();
int x = iframeLoc.getX();
int y = iframeLoc.getY();
driver.switchTo().frame(iframe);
WebElement element = driver.findElement(elementLocator);
Point elementLoc = element.getLocation();
x += elementLoc.getX();
y += elementLoc.getY();
p = new Point(x, y);
return p;