Using Java Selenium, I have a reference to a WebElement
object that represents the following HTML node:
<td role="gridcell" class="mat-calendar-body-cell ng-star-inserted" style="width: 25%; padding-top: 7.14286%; padding-bottom: 7.14286%;" tabindex="-1" data-mat-row="0" data-mat-col="0" aria-label="2001" aria-selected="false">...</td>
I need the 2001 value of the aria-label
attribute, but I can’t seem to able to. The following method invocations all return null
and I don’t know why:
element.getAttribute("aria-label");
element.getAttribute("ariaLabel");
element.getDomAttribute("aria-label");
element.getDomAttribute("ariaLabel");
element.getDomProperty("aria-label");
element.getDomProperty("ariaLabel");
The reason for trying both aria-label
and ariaLabel
is that it’s listed as ariaLabel
in the properties list:
I printed out the values of all other attributes of this node to verify that it’s not a timing issue, and, curiously, this was the output:
role: gridcell
class: mat-calendar-body-cell-container ng-star-inserted
style: width: 25%; padding-top: 7.14286%; padding-bottom: 7.14286%;
tabindex: null
data-mat-row: 0
data-mat-col: 0
aria-label: null
aria-selected: null
How can I get the value of aria-label
?
Selenium version: 4.15.0
Chromedriver version: 122.0.6261.57
2
Answers
The website version I was automating against had been updated to move the
aria-label
attribute from thetd
node to a childbutton
node; I just hadn't bothered refreshing the page yet.As you listed first , this should work: element.getAttribute("aria-label");