Skip to content

Commit

Permalink
[atoms] use css locators in dom.js (#13430)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 authored Mar 25, 2024
1 parent 3184040 commit af49a5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
15 changes: 8 additions & 7 deletions javascript/atoms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ closure_js_library(
deps = [
":bot",
":color",
":css",
":domcore",
":json",
":useragent",
":xpath",
"@io_bazel_rules_closure//closure/library",
],
)
Expand Down Expand Up @@ -239,7 +239,7 @@ closure_js_library(
name = "locators",
srcs = glob(
["locators/*.js"],
exclude = ["locators/xpath.js"],
exclude = ["locators/css.js"],
),
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
Expand All @@ -250,11 +250,12 @@ closure_js_library(
],
deps = [
":bot",
":css",
":dom",
":errors",
":json",
":useragent",
":xpath",
"//third_party/js/wgxpath",
"@io_bazel_rules_closure//closure/library",
],
)
Expand Down Expand Up @@ -289,8 +290,8 @@ closure_js_library(
)

closure_js_library(
name = "xpath",
srcs = ["locators/xpath.js"],
name = "css",
srcs = ["locators/css.js"],
suppress = [
"JSC_IMPLICITLY_NULLABLE_JSDOC",
"JSC_STRICT_INEXISTENT_PROPERTY",
Expand All @@ -300,7 +301,7 @@ closure_js_library(
deps = [
":bot",
":errors",
"//third_party/js/wgxpath",
":useragent",
"@io_bazel_rules_closure//closure/library",
],
)
Expand Down Expand Up @@ -331,6 +332,7 @@ closure_js_deps(
":action",
":bot",
":color",
":css",
":devices",
":dom",
":domcore",
Expand All @@ -343,7 +345,6 @@ closure_js_deps(
":test_util",
":useragent",
":window",
":xpath",
],
)

Expand Down
9 changes: 3 additions & 6 deletions javascript/atoms/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ goog.provide('bot.dom');
goog.require('bot');
goog.require('bot.color');
goog.require('bot.dom.core');
goog.require('bot.locators.xpath');
goog.require('bot.locators.css');
goog.require('bot.userAgent');
goog.require('goog.array');
goog.require('goog.dom');
Expand Down Expand Up @@ -878,15 +878,12 @@ bot.dom.maybeFindImageMap_ = function(elem) {
if (map && map.name) {
var mapDoc = goog.dom.getOwnerDocument(map);

// The "//*" XPath syntax can confuse the closure compiler, so we use
// the "/descendant::*" syntax instead.
// TODO: Try to find a reproducible case for the compiler bug.
// TODO: Restrict to applet, img, input:image, and object nodes.
var imageXpath = '/descendant::*[@usemap = "#' + map.name + '"]';
var locator = '*[usemap="#' + map.name + '"]';

// TODO: Break dependency of bot.locators on bot.dom,
// so bot.locators.findElement can be called here instead.
image = bot.locators.xpath.single(imageXpath, mapDoc);
image = bot.locators.css.single(locator, mapDoc);

if (image) {
rect = bot.dom.getClientRect(image);
Expand Down

0 comments on commit af49a5e

Please sign in to comment.