Skip to content

Commit 999247b

Browse files
committed
Correcting IWebElement.GetScreenshot remote URL
1 parent a02a718 commit 999247b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

dotnet/src/webdriver/Remote/W3CWireProtocolCommandInfoRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="W3CWireProtocolCommandInfoRepository.cs" company="WebDriver Committers">
1+
// <copyright file="W3CWireProtocolCommandInfoRepository.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -108,7 +108,7 @@ protected override void InitializeCommandDictionary()
108108
this.TryAddCommand(DriverCommand.GetAlertText, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/alert/text"));
109109
this.TryAddCommand(DriverCommand.SetAlertValue, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/alert/text"));
110110
this.TryAddCommand(DriverCommand.Screenshot, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/screenshot"));
111-
this.TryAddCommand(DriverCommand.ElementScreenshot, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/screenshot/{id}"));
111+
this.TryAddCommand(DriverCommand.ElementScreenshot, new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/element/{id}/screenshot"));
112112

113113
// Commands below here are not included in the W3C specification,
114114
// but are required for full fidelity of execution with Selenium's

dotnet/test/common/TakesScreenshotTest.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using NUnit.Framework;
44

@@ -26,6 +26,26 @@ public void ShouldTakeScreenshotsOfThePage()
2626
File.Delete(filename);
2727
}
2828

29+
[Test]
30+
public void ShouldTakeScreenshotsOfAnElement()
31+
{
32+
driver.Url = simpleTestPage;
33+
IWebElement element = driver.FindElement(By.Id("multiline"));
34+
35+
ITakesScreenshot screenshotCapableElement = element as ITakesScreenshot;
36+
if (screenshotCapableElement == null)
37+
{
38+
return;
39+
}
40+
41+
string filename = Path.Combine(Path.GetTempPath(), "snapshot" + new Random().Next().ToString() + ".png");
42+
Screenshot screenImage = screenshotCapableElement.GetScreenshot();
43+
screenImage.SaveAsFile(filename, ScreenshotImageFormat.Png);
44+
Assert.IsTrue(File.Exists(filename));
45+
Assert.IsTrue(new FileInfo(filename).Length > 0);
46+
File.Delete(filename);
47+
}
48+
2949
[Test]
3050
public void CaptureToBase64()
3151
{

0 commit comments

Comments
 (0)