Skip to content

Commit 52f9967

Browse files
committed
Implements 'getDomAttribute' to get attribute value as defined by w3c spec and removes legacy command usages
1 parent 08a1917 commit 52f9967

3 files changed

Lines changed: 79 additions & 45 deletions

File tree

javascript/node/selenium-webdriver/lib/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ const W3C_COMMAND_MAP = new Map([
266266
],
267267
// Element interaction.
268268
[cmd.Name.GET_ELEMENT_TAG_NAME, get('/session/:sessionId/element/:id/name')],
269-
[cmd.Name.GET_DOM_ATTRIBUTE, get('/session/:sessionId/element/:id/attribute/name')],
269+
[cmd.Name.GET_DOM_ATTRIBUTE, get('/session/:sessionId/element/:id/attribute/:name')],
270270
[
271271
cmd.Name.GET_ELEMENT_ATTRIBUTE,
272272
(cmd) => {

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,21 +1951,6 @@ class Window {
19511951
new command.Command(command.Name.GET_WINDOW_RECT)
19521952
)
19531953
} catch (ex) {
1954-
if (ex instanceof error.UnknownCommandError) {
1955-
let { width, height } = await this.driver_.execute(
1956-
new command.Command(command.Name.GET_WINDOW_SIZE).setParameter(
1957-
'windowHandle',
1958-
'current'
1959-
)
1960-
)
1961-
let { x, y } = await this.driver_.execute(
1962-
new command.Command(command.Name.GET_WINDOW_POSITION).setParameter(
1963-
'windowHandle',
1964-
'current'
1965-
)
1966-
)
1967-
return { x, y, width, height }
1968-
}
19691954
throw ex
19701955
}
19711956
}
@@ -1995,26 +1980,6 @@ class Window {
19951980
})
19961981
)
19971982
} catch (ex) {
1998-
if (ex instanceof error.UnknownCommandError) {
1999-
if (typeof x === 'number' && typeof y === 'number') {
2000-
await this.driver_.execute(
2001-
new command.Command(command.Name.SET_WINDOW_POSITION)
2002-
.setParameter('windowHandle', 'current')
2003-
.setParameter('x', x)
2004-
.setParameter('y', y)
2005-
)
2006-
}
2007-
2008-
if (typeof width === 'number' && typeof height === 'number') {
2009-
await this.driver_.execute(
2010-
new command.Command(command.Name.SET_WINDOW_SIZE)
2011-
.setParameter('windowHandle', 'current')
2012-
.setParameter('width', width)
2013-
.setParameter('height', height)
2014-
)
2015-
}
2016-
return this.getRect()
2017-
}
20181983
throw ex
20191984
}
20201985
}
@@ -2653,6 +2618,36 @@ class WebElement {
26532618
)
26542619
}
26552620

2621+
/**
2622+
* Get the value of the given attribute of the element.
2623+
* <p>
2624+
* This method, unlike {@link #getAttribute(String)}, returns the value of the attribute with the
2625+
* given name but not the property with the same name.
2626+
* <p>
2627+
* The following are deemed to be "boolean" attributes, and will return either "true" or null:
2628+
* <p>
2629+
* async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,
2630+
* defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,
2631+
* iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade,
2632+
* novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless,
2633+
* seeking, selected, truespeed, willvalidate
2634+
* <p>
2635+
* See <a href="https://w3c.github.io/webdriver/#get-element-attribute">W3C WebDriver specification</a>
2636+
* for more details.
2637+
*
2638+
* @param attributeName The name of the attribute.
2639+
* @return The attribute's value or null if the value is not set.
2640+
*/
2641+
2642+
getDomAttribute(attributeName) {
2643+
return this.execute_(
2644+
new command.Command(command.Name.GET_DOM_ATTRIBUTE).setParameter(
2645+
'name',
2646+
attributeName
2647+
)
2648+
)
2649+
}
2650+
26562651
/**
26572652
* Get the given property of the referenced web element
26582653
* @param {string} propertyName The name of the attribute to query.
@@ -2721,15 +2716,7 @@ class WebElement {
27212716
new command.Command(command.Name.GET_ELEMENT_RECT)
27222717
)
27232718
} catch (err) {
2724-
if (err instanceof error.UnknownCommandError) {
2725-
const { width, height } = await this.execute_(
2726-
new command.Command(command.Name.GET_ELEMENT_SIZE)
2727-
)
2728-
const { x, y } = await this.execute_(
2729-
new command.Command(command.Name.GET_ELEMENT_LOCATION)
2730-
)
2731-
return { x, y, width, height }
2732-
}
2719+
throw err;
27332720
}
27342721
}
27352722

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Software Freedom Conservancy (SFC) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The SFC licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
'use strict'
21+
22+
const assert = require('assert')
23+
const { By, Browser } = require('../../index')
24+
const { Pages, ignore, suite } = require('../../lib/test')
25+
26+
suite(function (env) {
27+
const browsers = (...args) => env.browsers(...args)
28+
29+
let driver
30+
31+
before(async function () {
32+
driver = await env.builder().build()
33+
})
34+
35+
after(function () {
36+
return driver.quit()
37+
})
38+
39+
describe('Api Tests', function () {
40+
ignore(browsers(Browser.SAFARI)).it('getDomAttribute test', async function () {
41+
await driver.get(Pages.formPage)
42+
const element = await driver.findElement(By.id("vsearchGadget"))
43+
const attr = await element.getDomAttribute("accesskey");
44+
assert.strictEqual(attr, '4')
45+
})
46+
})
47+
})

0 commit comments

Comments
 (0)