If driver switched to iframe, selenium would take screenshot of iframe content only
I tried to reproduce your issue and looks like you are not completely right. In my case when I took the screen-shot it contained the entire page despite I switched to iFrame before.
if it's possible to get location of an element relative to iframe and not the whole screen?
getLocation method returns you the position relative to iFrame. I.e. exactly what you need. So in order to get the position of an element in the entire view you should take the position of iframe in the parent view and add the position of the elemetn in iframe. Here is the proof-of-concept:
Test site: https://jsfiddle.net/o1kqLahu/5/
Code:
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver", "C:\\Temp\\chromedriver.exe");
WebDriver chromeDriver = new ChromeDriver();
chromeDriver.get("https://jsfiddle.net/o1kqLahu/5/");
Point locationOfIFrame = chromeDriver.findElement(By.name("result")).getLocation();
System.out.println("X: " + locationOfIFrame.x + "; Y: " + locationOfIFrame.y);
chromeDriver.switchTo().frame("result");
Point locationInIFrame = chromeDriver.findElement(By.id("secret-input")).getLocation();
File scrFile = ((TakesScreenshot)chromeDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\Temp\\screenshot2.png"));
System.out.println("Location of element in iframe: X: "
+ locationInIFrame.x + "; Y: " + locationInIFrame.y);
System.out.println("Location of element of the screen: X: " +
(locationInIFrame.x + locationOfIFrame.x) +
"; Y: " +
(locationInIFrame.y + locationOfIFrame.y));
chromeDriver.close();
}
Output:
X: 570; Y: 474
Location of element in iframe: X: 8; Y: 8
Location of element of the screen: X: 578; Y: 482
Some screens saved:


UPD:
In case of the defect in geko-driver (as per the update of your question) I would recommend the following workaround:
- Take iFrame position before switching to that iFrame
- Take position of the required element (related to the entire screen)
- Take screenshot.
Now we have the picture of the iFrame content and we can calculate the position of the element inside the iFrame using the following formula:
PositionOfElementInsideIFrame = PositionOfTheElementInsideEntireScreen - PositionOfIFrameInsideEntireScreen