Skip to content

Instantly share code, notes, and snippets.

@cmin764
Created February 21, 2022 11:56
Show Gist options
  • Select an option

  • Save cmin764/afe964620d82e8420d3c1684ad9b3f95 to your computer and use it in GitHub Desktop.

Select an option

Save cmin764/afe964620d82e8420d3c1684ad9b3f95 to your computer and use it in GitHub Desktop.
Extends `RPA.Browser.Selenium` with setting attribute capability
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