Skip to content

Commit 6e1e6c1

Browse files
p0dejebarancev
authored andcommitted
firefox: Check that image using map is clickable when clicking area
Signed-off-by: Alexei Barantsev <[email protected]>
1 parent a98f672 commit 6e1e6c1

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

javascript/firefox-driver/js/syntheticMouse.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,17 @@ SyntheticMouse.prototype.isElementShown = function(element) {
9999

100100

101101
SyntheticMouse.prototype.isElementClickable = function(element) {
102+
// get the outermost ancestor of the element. This will be either the document
103+
// or a shadow root.
104+
var owner = element;
105+
while (owner.parentNode) {
106+
owner = owner.parentNode;
107+
}
108+
109+
var tagName = element.tagName.toLowerCase();
110+
102111
// Check to see if this is an option element. If it is, and the parent isn't a multiple
103112
// select, then check that select is clickable.
104-
var tagName = element.tagName.toLowerCase();
105113
if ('option' == tagName) {
106114
var parent = element;
107115
while (parent.parentNode != null && parent.tagName.toLowerCase() != 'select') {
@@ -113,11 +121,25 @@ SyntheticMouse.prototype.isElementClickable = function(element) {
113121
}
114122
}
115123

116-
// get the outermost ancestor of the element. This will be either the document
117-
// or a shadow root.
118-
var owner = element;
119-
while (owner.parentNode) {
120-
owner = owner.parentNode;
124+
// Check to see if this is an area element. If it is, find the image element that
125+
// uses area's map, then check that image is clickable.
126+
if ('area' == tagName) {
127+
var map = element.parentElement;
128+
if (map.tagName.toLowerCase() != 'map') {
129+
throw new Error('the area is not within a map');
130+
}
131+
var mapName = map.getAttribute('name');
132+
if (mapName == null) {
133+
throw new Error ("area's parent map must have a name");
134+
}
135+
mapName = '#' + mapName.toLowerCase();
136+
var images = owner.getElementsByTagName('img');
137+
for (var i = 0; i < images.length; i++) {
138+
var image = images[i];
139+
if (image.useMap.toLowerCase() == mapName) {
140+
return this.isElementClickable(image);
141+
}
142+
}
121143
}
122144

123145
var rect = bot.dom.getClientRect(element);

0 commit comments

Comments
 (0)