Skip to content

Commit 936d5ce

Browse files
author
Jani Mikkonen
committed
Set Element Attribute keyword added
1 parent decc300 commit 936d5ce

5 files changed

Lines changed: 44 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ tests do show they work.
159159

160160
* Returns a dict of default capabilties. Useful if you need to construct desired_capabilities and you dont need to remember all basic things you need to have. This is due to SeleniumLibrary not providing those defaults anymore if user provide their own.
161161

162+
* Set Element Attribute **locator** **attribute_name** **value**
163+
164+
* Sets arbituary attribute of the element into provided value
165+
162166
# Keyword Documentation
163167

164168
Keyword documentation [here](https://salabs.github.io/robotframework-seleniumtestability/index.html) and if you need to create one for offline usage:

assets/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
</table>
125125
<div id="container">
126126
<div id="navi"><button id="hiddenbutton">Should be overlayed</button></div>
127-
<div id="infoi">
127+
<div id="infoi" random_attribute="yey">
128128
<img src="http://placehold.it/100x100" height="100" width="100" />
129129
</div>
130130
</div>

atest/attributes.robot

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*** Settings ***
2+
Documentation Verifies webelement attribute getters/setters
3+
Suite Setup Start Flask App
4+
Suite Teardown Stop Flask App
5+
Test Teardown Teardown Web Environment
6+
Test Template Show And Hide Test
7+
Library SeleniumLibrary plugins=${CURDIR}/../src/SeleniumTestability;True;29 seconds;False
8+
Resource keywords.robot
9+
10+
*** Test Cases ***
11+
Set Attribute In Firefox
12+
${FF} ${URL}
13+
14+
Set Attribute In Chrome
15+
${GC} ${URL}
16+
17+
*** Keywords ***
18+
Show And Hide Test
19+
[Arguments] ${BROWSER} ${URL}
20+
[Documentation] Verifies Set Element Attribute
21+
Setup Web Environment ${BROWSER} ${URL}
22+
${x}= Get Element Attribute id:infoi random_attribute
23+
Should Be Equal ${x} yey
24+
Set Element Attribute id:infoi random_attribute NAY!
25+
${x}= Get Element Attribute id:infoi random_attribute
26+
Should Be Equal ${x} NAY!

src/SeleniumTestability/javascript.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@
4040
"get_element_at": """
4141
return document.elementFromPoint(arguments[0], arguments[1])
4242
""",
43+
"set_element_attribute": """
44+
arguments[0].setAttribute(arguments[1], arguments[2])
45+
""",
4346
}

src/SeleniumTestability/plugin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,13 @@ def get_default_capabilities(self: "SeleniumTestability", browser_name: str) ->
533533
except Exception as e:
534534
self.logger.debug(e)
535535
return None
536+
537+
538+
@log_wrapper
539+
@keyword
540+
def set_element_attribute(self: "SeleniumTestability", locator: LocatorType, attribute: str, value: str) -> None:
541+
"""
542+
Sets ``locator`` attribute ``attribute`` to ``value``
543+
"""
544+
from_element = self.el.find_element(locator)
545+
self.ctx.driver.execute_script(JS_LOOKUP["set_element_attribute"], from_element, attribute, value)

0 commit comments

Comments
 (0)