Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/src/web/svgTest.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions java/client/test/org/openqa/selenium/Pages.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class Pages {
public String slowIframes;
public String slowLoadingAlertPage;
public String svgPage;
public String svgTestPage;
public String tables;
public String underscorePage;
public String unicodeLtrPage;
Expand Down Expand Up @@ -123,6 +124,7 @@ public Pages(AppServer appServer) {
slowIframes = appServer.whereIs("slow_loading_iframes.html");
slowLoadingAlertPage = appServer.whereIs("slowLoadingAlert.html");
svgPage = appServer.whereIs("svgPiechart.xhtml");
svgTestPage = appServer.whereIs("svgTest.svg");
tables = appServer.whereIs("tables.html");
underscorePage = appServer.whereIs("underscore.html");
unicodeLtrPage = appServer.whereIs("utf8/unicode_ltr.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
SlowLoadingPageTest.class,
StaleElementReferenceTest.class,
SvgElementTest.class,
SvgDocumentTest.class
TagNameTest.class,
TakesScreenshotTest.class,
TextHandlingTest.class,
Expand Down
56 changes: 56 additions & 0 deletions java/client/test/org/openqa/selenium/SvgDocumentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2007-2012 Selenium committers
Portions copyright 2011-2012 Software Freedom Conservancy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package org.openqa.selenium;

import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.testing.Ignore;
import org.openqa.selenium.testing.JUnit4TestBase;

import static org.junit.Assert.assertEquals;
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
import static org.openqa.selenium.testing.Ignore.Driver.IE;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA;
import static org.openqa.selenium.testing.Ignore.Driver.OPERA_MOBILE;
import static org.openqa.selenium.testing.Ignore.Driver.SELENESE;

@Ignore(value = {HTMLUNIT, IE, OPERA, OPERA_MOBILE, SELENESE},
reason = "HtmlUnit: SVG interaction is only implemented in rendered browsers")
public class SvgDocumentTest extends JUnit4TestBase {

@Test
public void testClickOnSvgElement() {
driver.get(pages.svgTestPage);
WebElement rect = driver.findElement(By.id("rect"));

assertEquals("blue", rect.getAttribute("fill"));
rect.click();
assertEquals("green", rect.getAttribute("fill"));
}

@Test
public void testExecuteScriptInSvgDocument() {
driver.get(pages.svgTestPage);
WebElement rect = driver.findElement(By.id("rect"));

assertEquals("blue", rect.getAttribute("fill"));
((JavascriptExecutor) driver).executeScript("document.getElementById('rect').setAttribute('fill', 'yellow');");
assertEquals("yellow", rect.getAttribute("fill"));
}

}
6 changes: 5 additions & 1 deletion javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,11 @@ bot.action.LegacyDevice_.findAncestorForm = function(element) {
*/
bot.action.scrollIntoView = function(element, opt_coords) {
if (!bot.dom.isScrolledIntoView(element, opt_coords)) {
element.scrollIntoView();
// Some elements may not have a scrollIntoView function - for example,
// elements under an SVG element. Call those only if they exist.
if (typeof element.scrollIntoView == 'function') {
element.scrollIntoView();
}
// In Opera 10, scrollIntoView only scrolls the element into the viewport of
// its immediate parent window, so we explicitly scroll the ancestor frames
// into view of their respective windows. Note that scrolling the top frame
Expand Down
4 changes: 2 additions & 2 deletions javascript/atoms/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,8 +1240,8 @@ bot.dom.scrollElementRegionIntoClientView = function(elem, elemRegion) {
var viewportSize = goog.dom.getDomHelper(doc).getViewportSize();

var region = new goog.math.Rect(
elemPageOffset.x + elemRegion.left - doc.body.scrollLeft,
elemPageOffset.y + elemRegion.top - doc.body.scrollTop,
elemPageOffset.x + elemRegion.left - (doc.body ? doc.body.scrollLeft : 0),
elemPageOffset.y + elemRegion.top - (doc.body ? doc.body.scrollTop : 0),
viewportSize.width - elemRegion.width,
viewportSize.height - elemRegion.height);

Expand Down
11 changes: 6 additions & 5 deletions javascript/firefox-driver/js/firefoxDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,18 @@ function injectAndExecuteScript(respond, parameters, isAsync, timer) {
// Attach the listener to the DOM
var addListener = function() {
if (!doc.getUserData('webdriver-evaluate-attached')) {
var element = doc.createElement('script');
var parentNode = Utils.getMainDocumentElement(doc);
var element = Utils.isSVG(doc) ? doc.createElementNS("http://www.w3.org/2000/svg", "script") : doc.createElement('script');
element.setAttribute('type', 'text/javascript');
element.innerHTML = FirefoxDriver.listenerScript;
doc.body.appendChild(element);
element.parentNode.removeChild(element);
element.textContent = FirefoxDriver.listenerScript;
parentNode.appendChild(element);
parentNode.removeChild(element);
}
timer.runWhenTrue(checkScriptLoaded, runScript, 10000, scriptLoadTimeOut);
};

var checkDocBodyLoaded = function() {
return !!doc.body;
return !!Utils.getMainDocumentElement(doc);
};

timer.runWhenTrue(checkDocBodyLoaded, addListener, 10000, docBodyLoadTimeOut);
Expand Down
3 changes: 2 additions & 1 deletion javascript/firefox-driver/js/syntheticMouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ SyntheticMouse.prototype.move = function(target, xOffset, yOffset) {
// Are we about to be dragged out of the window?

var isOption = bot.dom.isElement(element, goog.dom.TagName.OPTION);
var isSVG = Utils.isSVG(element.ownerDocument);

if (!isOption && !inViewAfterScroll) {
if (!isOption && !isSVG && !inViewAfterScroll) {
return SyntheticMouse.newResponse(bot.ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS,
'Element cannot be scrolled into view:' + element);
}
Expand Down
21 changes: 16 additions & 5 deletions javascript/firefox-driver/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Utils.getActiveElement = function(doc) {

// Default to the body
if (!element) {
element = doc.body;
element = Utils.getMainDocumentElement(doc);
}

return element;
Expand Down Expand Up @@ -1176,8 +1176,8 @@ Utils.getPageUnloadedIndicator = function(element) {
var unloadFunction = function() { toReturn.wasUnloaded = true };
toReturn.callback = unloadFunction;

element.ownerDocument.body.addEventListener('unload',
unloadFunction, false);
var mainDocumentElement = Utils.getMainDocumentElement(element.ownerDocument);
mainDocumentElement.addEventListener('unload', unloadFunction, false);

// This is a Firefox specific event - See:
// https://developer.mozilla.org/En/Using_Firefox_1.5_caching
Expand All @@ -1191,8 +1191,9 @@ Utils.removePageUnloadEventListener = function(element, pageUnloadData) {
if (pageUnloadData.callback) {
// Remove event listeners...
if (element.ownerDocument) {
if (element.ownerDocument.body) {
element.ownerDocument.body.removeEventListener('unload',
var mainDocumentElement = Utils.getMainDocumentElement(element.ownerDocument);
if (mainDocumentElement) {
mainDocumentElement.removeEventListener('unload',
pageUnloadData.callback, false);
}
if (element.ownerDocument.defaultView) {
Expand Down Expand Up @@ -1227,3 +1228,13 @@ Utils.convertNSIArrayToNative = function(arrayToConvert) {

return returnArray;
};

Utils.isSVG = function(doc) {
return doc.documentElement && doc.documentElement.nodeName == 'svg';
};

Utils.getMainDocumentElement = function(doc) {
if (Utils.isSVG(doc))
return doc.documentElement;
return doc.body;
};
6 changes: 4 additions & 2 deletions javascript/firefox-driver/js/wrappedElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ WebElement.clickElement = function(respond, parameters) {
unwrapped,
new goog.math.Coordinate(elementHalfWidth, elementHalfHeight));

if (!inViewAfterScroll) {
var isSVG = Utils.isSVG(element.ownerDocument);

if (!isSVG && !inViewAfterScroll) {
respond.sendError(
new WebDriverError(bot.ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS,
'Element cannot be scrolled into view:' + element));
Expand Down Expand Up @@ -388,7 +390,7 @@ WebElement.getElementLocationOnceScrolledIntoView = function(
respond.session.getDocument());

var theDoc = element.ownerDocument;
theDoc.body.focus();
Utils.getMainDocumentElement(theDoc).focus();
var elementLocation = Utils.getLocationOnceScrolledIntoView(element);

respond.value = {
Expand Down