Created
February 21, 2022 11:56
-
-
Save cmin764/afe964620d82e8420d3c1684ad9b3f95 to your computer and use it in GitHub Desktop.
Extends `RPA.Browser.Selenium` with setting attribute capability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Union | |
| from RPA.Browser.Selenium import Selenium | |
| from SeleniumLibrary.base import keyword | |
| from selenium.webdriver.remote.webelement import WebElement | |
| class ExtendedSelenium(Selenium): | |
| @keyword | |
| def set_attribute_to_element( | |
| self, | |
| locator: Union[WebElement, str], | |
| attribute: str, | |
| value: str | |
| ): | |
| """Sets an attribute value to the element identified by ``locator``.""" | |
| element = self.find_element(locator) | |
| self.driver.execute_script( | |
| f"arguments[0].setAttribute('{attribute}', '{value}');", | |
| element | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment