Skip to content

Commit

Permalink
JimEvans: Modifying IE element finding native code to properly escape…
Browse files Browse the repository at this point in the history
… double-quotes and backslashes. Fixes issue SeleniumHQ#2049.

r12920
  • Loading branch information
jimevans committed Jul 13, 2011
1 parent 5cd36c0 commit b064962
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 2 deletions.
33 changes: 31 additions & 2 deletions WebDriver.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "web", "common\src\web", "{DB560F4B-1F41-4E8E-AC06-640D736E8A72}"
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "web", "common\src\web\", "{DB560F4B-1F41-4E8E-AC06-640D736E8A72}"
ProjectSection(WebsiteProperties) = preProject
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0"
Debug.AspNetCompiler.VirtualPath = "/web"
Expand All @@ -27,7 +27,8 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webdriver-interactions", "cpp\webdriver-interactions\webdriver-interactions.vcxproj", "{87FA39A1-958E-478A-8AB9-6D5E5AAA3886}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webdriver-firefox", "cpp\webdriver-firefox\webdriver-firefox.vcxproj", "{A9D3BB2D-FD1E-43A2-80F6-F8320682323E}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webdriver-firefox-5", "cpp\webdriver-firefox\webdriver-firefox-5.vcxproj", "{A9D3BB2D-FD1E-43A2-80F6-F8320682323E}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webdriver-firefox-5", "cpp\webdriver-firefox\webdriver-firefox-5.vcxproj", "{FD15C665-943A-43A5-B93A-D16291706BE0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IEDriver", "cpp\IEDriver\IEDriver.vcxproj", "{BB72383B-427F-4191-B692-E4345A30E33C}"
EndProject
Expand Down Expand Up @@ -63,6 +64,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDriver.Android.Tests", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDriver", "dotnet\src\WebDriver\WebDriver.csproj", "{83C13931-B27C-425C-AAF0-5F96EEA4F173}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "webdriver-server", "cpp\webdriver-server\webdriver-server.vcxproj", "{35A23A16-EF17-4CC3-8854-785025A304F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|.NET = Debug|.NET
Expand Down Expand Up @@ -117,6 +120,16 @@ Global
{A9D3BB2D-FD1E-43A2-80F6-F8320682323E}.Release|Win32.ActiveCfg = Release|Win32
{A9D3BB2D-FD1E-43A2-80F6-F8320682323E}.Release|Win32.Build.0 = Release|Win32
{A9D3BB2D-FD1E-43A2-80F6-F8320682323E}.Release|x64.ActiveCfg = Release|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Debug|.NET.ActiveCfg = Debug|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Debug|Any CPU.ActiveCfg = Debug|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Debug|Win32.ActiveCfg = Debug|Win32
{FD15C665-943A-43A5-B93A-D16291706BE0}.Debug|x64.ActiveCfg = Debug|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Release|.NET.ActiveCfg = Release|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Release|Any CPU.ActiveCfg = Release|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Release|Mixed Platforms.ActiveCfg = Release|x64
{FD15C665-943A-43A5-B93A-D16291706BE0}.Release|Win32.ActiveCfg = Release|Win32
{FD15C665-943A-43A5-B93A-D16291706BE0}.Release|x64.ActiveCfg = Release|x64
{BB72383B-427F-4191-B692-E4345A30E33C}.Debug|.NET.ActiveCfg = Debug|x64
{BB72383B-427F-4191-B692-E4345A30E33C}.Debug|Any CPU.ActiveCfg = Debug|Win32
{BB72383B-427F-4191-B692-E4345A30E33C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
Expand Down Expand Up @@ -361,6 +374,22 @@ Global
{83C13931-B27C-425C-AAF0-5F96EEA4F173}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{83C13931-B27C-425C-AAF0-5F96EEA4F173}.Release|Win32.ActiveCfg = Release|Any CPU
{83C13931-B27C-425C-AAF0-5F96EEA4F173}.Release|x64.ActiveCfg = Release|Any CPU
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|.NET.ActiveCfg = Debug|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|Any CPU.ActiveCfg = Debug|x64
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|Win32.ActiveCfg = Debug|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|Win32.Build.0 = Debug|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|x64.ActiveCfg = Debug|x64
{35A23A16-EF17-4CC3-8854-785025A304F3}.Debug|x64.Build.0 = Debug|x64
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|.NET.ActiveCfg = Release|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|Any CPU.ActiveCfg = Release|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|Mixed Platforms.Build.0 = Release|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|Win32.ActiveCfg = Release|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|Win32.Build.0 = Release|Win32
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|x64.ActiveCfg = Release|x64
{35A23A16-EF17-4CC3-8854-785025A304F3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions common/src/web/simpleTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ <h1>Heading</h1>
<a href="" id="linkWithTrailingSpace">link with trailing space
</a>
<a href=""><b>link with formatting tags</b></a>
<a href="" id="quote">link with " (double quote)</a>
<a href="" id="squote">link with ' (single quote)</a>
<a href="" id="backslash">link with \ (backslash)</a>
</div>

<div name="someDiv">Top level</div>
Expand Down
3 changes: 3 additions & 0 deletions cpp/IEDriver/CommandHandlers/FindChildElementCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class FindChildElementCommandHandler : public IECommandHandler {
std::wstring mechanism = CA2W(using_parameter_iterator->second.asString().c_str(), CP_UTF8);
std::wstring value = CA2W(value_parameter_iterator->second.asString().c_str(), CP_UTF8);

StringUtilities::ReplaceAllSubstrings(L"\\", L"\\\\", &value);
StringUtilities::ReplaceAllSubstrings(L"\"", L"\\\"", &value);

std::wstring mechanism_translation;
int status_code = executor.GetElementFindMethod(mechanism, &mechanism_translation);
if (status_code != SUCCESS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class FindChildElementsCommandHandler : public IECommandHandler {
std::wstring mechanism = CA2W(using_parameter_iterator->second.asString().c_str(), CP_UTF8);
std::wstring value = CA2W(value_parameter_iterator->second.asString().c_str(), CP_UTF8);

StringUtilities::ReplaceAllSubstrings(L"\\", L"\\\\", &value);
StringUtilities::ReplaceAllSubstrings(L"\"", L"\\\"", &value);

std::wstring mechanism_translation;
int status_code = executor.GetElementFindMethod(mechanism, &mechanism_translation);
if (status_code != SUCCESS) {
Expand Down
3 changes: 3 additions & 0 deletions cpp/IEDriver/CommandHandlers/FindElementCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class FindElementCommandHandler : public IECommandHandler {
std::wstring mechanism = CA2W(using_parameter_iterator->second.asString().c_str(), CP_UTF8);
std::wstring value = CA2W(value_parameter_iterator->second.asString().c_str(), CP_UTF8);

StringUtilities::ReplaceAllSubstrings(L"\\", L"\\\\", &value);
StringUtilities::ReplaceAllSubstrings(L"\"", L"\\\"", &value);

std::wstring mechanism_translation;
int status_code = executor.GetElementFindMethod(mechanism, &mechanism_translation);
if (status_code != SUCCESS) {
Expand Down
3 changes: 3 additions & 0 deletions cpp/IEDriver/CommandHandlers/FindElementsCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class FindElementsCommandHandler : public IECommandHandler {
std::wstring mechanism = CA2W(using_parameter_iterator->second.asString().c_str(), CP_UTF8);
std::wstring value = CA2W(value_parameter_iterator->second.asString().c_str(), CP_UTF8);

StringUtilities::ReplaceAllSubstrings(L"\\", L"\\\\", &value);
StringUtilities::ReplaceAllSubstrings(L"\"", L"\\\"", &value);

std::wstring mechanism_translation;
int status_code = executor.GetElementFindMethod(mechanism, &mechanism_translation);
if (status_code != SUCCESS) {
Expand Down
1 change: 1 addition & 0 deletions cpp/IEDriver/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <atlwin.h>
#include <comdef.h>
#include <comutil.h>
#include "string_utilities.h"

// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
Expand Down
Binary file modified cpp/prebuilt/Win32/Release/IEDriver.dll
Binary file not shown.
Binary file modified cpp/prebuilt/x64/Release/IEDriver.dll
Binary file not shown.
16 changes: 16 additions & 0 deletions dotnet/test/WebDriver.Common.Tests/ElementFindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ public void ShouldFindElementByLinkTextContainingEqualsSign()
Assert.AreEqual("linkWithEqualsSign", element.GetAttribute("id"));
}

[Test]
public void ShouldFindElementByLinkTextContainingDoubleQuote()
{
driver.Url = simpleTestPage;
IWebElement element = driver.FindElement(By.LinkText("link with \" (double quote)"));
Assert.AreEqual("quote", element.GetAttribute("id"));
}

[Test]
public void ShouldFindElementByLinkTextContainingBackslash()
{
driver.Url = simpleTestPage;
IWebElement element = driver.FindElement(By.LinkText("link with \\ (backslash)"));
Assert.AreEqual("backslash", element.GetAttribute("id"));
}

[Test]
public void ShouldFindElementByPartialLinkTextContainingEqualsSign()
{
Expand Down

0 comments on commit b064962

Please sign in to comment.