I want to change value of table header's aria-label
attribute using execute_script
HTML
of target element:
<th class="sorting" tabindex="0" rowspan="1" colspan="1" aria-label="Activate to sort column ascending">Company</th>
So I try following:
driver.execute_script('document.getElementsByTagName("th")[1].aria-label="Activate to sort column descending";')
but get exception:
WebDriverException: Message: unknown error: Runtime.evaluate threw exception: ReferenceError: Invalid left-hand side in assignment
If to use
driver.execute_script('document.getElementsByTagName("th")[1].["aria-label"]="Activate to sort column descending";')
got
WebDriverException: Message: unknown error: Runtime.evaluate threw exception: SyntaxError: Unexpected token
So what is the correct statement to set aria-label
new value?
Since aria-label
is an attribute, you should use .setAttribute(...)
:
driver.execute_script("document.getElementsByTagName('th')[1].setAttribute('aria-label', 'Activate to sort column descending');")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With