C# Selenium获取页面相对于页面开头的位置

C# Selenium获取页面相对于页面开头的位置,c#,selenium,position,C#,Selenium,Position,我正在将Selenium remotewebdriver与Nunit和c一起使用。当我发现错误时,我希望能够滚动到发生错误的位置,然后拍摄屏幕截图。这就是我想要实现这个方法的方式 public void ScrollToLocation(Point location) { //code to find position of the page var windowLocation = code to find position var yOffset = locatio

我正在将Selenium remotewebdriver与Nunit和c一起使用。当我发现错误时,我希望能够滚动到发生错误的位置,然后拍摄屏幕截图。这就是我想要实现这个方法的方式

public void ScrollToLocation(Point location)
{
    //code to find position of the page
    var windowLocation = code to find position

    var yOffset = location.Y - windowLocation.Y;

    IJavaScriptExecutor js = (IJavaScriptExecutor)webDriver;
    js.ExecuteScript("javascript:window.scrollBy(0," + yOffset + ")");
}
问题是我不知道如何找到页面的相对位置。例如,如果向下滚动页面,使我在屏幕上看到的页面左上角距离整个页面的0,0位置向下50像素,我希望找到50像素

我曾经想到过一种工作方式,只需向上滚动10000px,然后向下滚动location.Y,但我并不喜欢这种方式


编辑:由于种种原因,我忘了提及,我无法使用GetElementLocationOnCeScrolledToView查看

您真的需要滚动吗?仅仅在当前点截图还不够吗?你试过了吗?我曾经遇到过这样一种情况,你必须显式地滚动才能完成某件事。你能在某个特定点截图吗?如果是这样的话,我的问题就解决了。这就是我截图的方式。Response screenshotResponse=this.ExecuteDriverCommand.Screenshot,null;字符串base64=screenshotResponse.Value.ToString;