Skip to content

Commit 7cdb441

Browse files
committed
Take document mode into account when getting size of view port of IE.
When clicking elements in IE, we need to know if the element is in the view port, and this includes scroll bar calculations. However for sites that attempt to hide the vertical scroll bar in IE, this may result in different sizes based on the document rendering mode. Includes tests for clicking on a link at the very bottom of the view port.
1 parent b9ea4db commit 7cdb441

File tree

9 files changed

+86
-5
lines changed

9 files changed

+86
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Fixed footer with no scrollbar</title>
5+
</head>
6+
<body>
7+
<div style="width: 100%; min-height: 100%;">
8+
<div style="position: absolute; bottom: 0px;">
9+
<a id="link" href="xhtmlTest.html">Click me</a>
10+
</div>
11+
</div>
12+
</body>
13+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<title>Fixed footer with no scrollbar</title>
4+
</head>
5+
<body>
6+
<div style="width: 100%; min-height: 100%;">
7+
<div style="position: absolute; bottom: 0px;">
8+
<a id="link" href="xhtmlTest.html">Click me</a>
9+
</div>
10+
</div>
11+
</body>
12+
</html>

cpp/iedriver/Element.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ bool Element::GetClickableViewPortLocation(const bool document_contains_frames,
787787
return false;
788788
}
789789

790+
790791
long window_width = window_info.rcClient.right - window_info.rcClient.left;
791792
long window_height = window_info.rcClient.bottom - window_info.rcClient.top;
792793

@@ -797,20 +798,22 @@ bool Element::GetClickableViewPortLocation(const bool document_contains_frames,
797798
if (!document_contains_frames) {
798799
CComPtr<IHTMLDocument2> doc;
799800
this->GetContainingDocument(false, &doc);
801+
int document_mode = DocumentHost::GetDocumentMode(doc);
800802
CComPtr<IHTMLDocument3> document_element_doc;
801803
HRESULT hr = doc->QueryInterface<IHTMLDocument3>(&document_element_doc);
802-
if (SUCCEEDED(hr) && document_element_doc) {
804+
if (SUCCEEDED(hr) && document_element_doc && document_mode > 5) {
803805
CComPtr<IHTMLElement> document_element;
804-
document_element_doc->get_documentElement(&document_element);
806+
hr = document_element_doc->get_documentElement(&document_element);
805807
CComPtr<IHTMLElement2> size_element;
806-
document_element->QueryInterface<IHTMLElement2>(&size_element);
808+
hr = document_element->QueryInterface<IHTMLElement2>(&size_element);
807809
size_element->get_clientHeight(&window_height);
808810
size_element->get_clientWidth(&window_width);
809811
} else {
810812
// This branch is only included if getting documentElement fails.
811813
LOG(WARN) << "Document containing element does not contains frames, "
812-
<< "but getting the documentElement property failed. The "
813-
<< "view port calculation may be inaccurate";
814+
<< "but getting the documentElement property failed, or the "
815+
<< "doctype has thrown the browser into pre-IE6 rendering. "
816+
<< "The view port calculation may be inaccurate";
814817
int vertical_scrollbar_width = ::GetSystemMetrics(SM_CXVSCROLL);
815818
window_width -= vertical_scrollbar_width;
816819
LocationInfo document_info;

cpp/iedriverserver/CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ available via the project downloads page. Changes in "revision" field indicate
99
private releases checked into the prebuilts directory of the source tree, but
1010
not made generally available on the downloads page.
1111

12+
v2.35.2.1
13+
=========
14+
* Take document mode into account when getting size of view port for element
15+
clicks.
16+
1217
v2.35.2.0
1318
=========
1419
* Updates to JavaScript automation atoms.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

dotnet/test/common/ClickTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,27 @@ public void ShouldBeAbleToClickOnAnElementInFrameGreaterThanTwoViewports()
298298

299299
WaitFor(() => { return driver.Title == "clicks"; });
300300
}
301+
302+
[Test]
303+
public void ShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter()
304+
{
305+
string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("fixedFooterNoScroll.html");
306+
driver.Url = url;
307+
308+
driver.FindElement(By.Id("link")).Click();
309+
WaitFor(() => { return driver.Title == "XHTML Test Page"; });
310+
Assert.AreEqual("XHTML Test Page", driver.Title);
311+
}
312+
313+
[Test]
314+
public void ShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMode()
315+
{
316+
string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("fixedFooterNoScrollQuirksMode.html");
317+
driver.Url = url;
318+
319+
driver.FindElement(By.Id("link")).Click();
320+
WaitFor(() => { return driver.Title == "XHTML Test Page"; });
321+
Assert.AreEqual("XHTML Test Page", driver.Title);
322+
}
301323
}
302324
}

java/client/test/org/openqa/selenium/ClickTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,30 @@ public void testShouldBeAbleToClickOnRTLLanguageLink() {
330330
waitFor(WaitingConditions.pageTitleToBe(driver, "clicks"));
331331
}
332332

333+
@Test
334+
@Ignore(value = {HTMLUNIT, OPERA, OPERA_MOBILE, ANDROID, IPHONE, MARIONETTE}, reason
335+
= "not tested")
336+
public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter() {
337+
String url = appServer.whereIs("fixedFooterNoScroll.html");
338+
driver.get(url);
339+
340+
WebElement element = driver.findElement(By.id("link"));
341+
element.click();
342+
343+
waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
344+
}
345+
346+
@Test
347+
@Ignore(value = {HTMLUNIT, OPERA, OPERA_MOBILE, ANDROID, IPHONE, MARIONETTE}, reason
348+
= "not tested")
349+
public void testShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMode() {
350+
String url = appServer.whereIs("fixedFooterNoScrollQuirksMode.html");
351+
driver.get(url);
352+
353+
WebElement element = driver.findElement(By.id("link"));
354+
element.click();
355+
356+
waitFor(WaitingConditions.pageTitleToBe(driver, "XHTML Test Page"));
357+
}
358+
333359
}

0 commit comments

Comments
 (0)