This is an issue with ChromeDriver 91, first reported in the Chromium bug tracker on May 3rd 2021.
I've described the problem and possible solutions/workarounds in more detail in this article.
In short, the Chromium team believes that a recent change to the ChromeDriver attribute endpoint has negatively impacted the behaviour of the GetElementAttribute
command, which now leads to WebElement.getAttribute
method returning null
instead of the actual value of the attribute.
The issue affects tools using the JsonWireProtocol
, such as Selenium WebDriver 3, which Protractor uses under the hood.
The solution recommended by the Chromium team is to use Selenium WebDriver 4 instead, and there's an ongoing effort to make Protractor use that too (if you're on GitHub, please consider upvoting this ticket). A thing to note is that Selenium WebDriver 4 deprecates a number of APIs, so tests will need to be updated to avoid using those (i.e. browser.actions()
).
A Selenium WebDriver 3-compatible fix has been proposed too, but isn't available at the time of writing (June 8th 2021).
If you'd like to use Chromium/ChromeDriver 91 with Protractor before the official fixes are available you have three options:
Use W3C protocol
You can explicitly enable support for W3C protocol (instead of the affected JsonWireProtocol) in protractor.conf.js
:
capabilities: {
'browserName': 'chrome',
'goog:chromeOptions': {
w3c: true,
args: [
'--headless',
]
},
}
Warning: Some APIs, like browser.actions()
are not compatible with the W3C mode and will break when this mode is enabled.
Fall back to injecting JavaScript
You can change your tests to fall back to retrieving the attribute value via JavaScript when getAttribute()
returns null
.
const attribute = await element.getAttribute(name).then(value => {
if (value !== null) {
return value;
}
return browser.executeScript(`
function getAttribute(webElement, attributeName) {
return webElement.getAttribute(attributeName);
})
`, element, name);
})
This is similar to how Serenity/JS acceptance testing framework does it under the hood.
Use Protractor with Serenity/JS
I've already implemented the above fallback strategy in Serenity/JS (view on GitHub), so if you're using Protractor with Serenity/JS, you need to updated any @serenity-js/*
modules to version 2.29.0 and it will just work with Chromium 91.
For example, if you have a widget like this:
<input type="checkbox" id="confirm" />
With Serenity/JS and Protractor, you'd retrieve any of the widget's attributes as follows:
import { actorCalled } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
import { Target } from '@serenity-js/protractor';
import { by } from 'protractor';
const confirmation = Target.the('confirmation checkbox')
.located(by.id('confirm'));
// in the test:
actorCalled('Alice').attemptsTo(
Ensure.that(
Attribute.of(confirmation).called('checked'),
equals('true')
),
);
To get started with Serenity/JS and Protractor:
Full disclosure, I'm the author of Serenity/JS
chromedriver
is compatible with the newchromium