Repository navigation
Allow keywords to use Web Elements in addition to Locator. #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a3da65f
d475be3
dabcabd
d980419
5d82653
7ad9866
4198266
da4259a
505e6b3
c7f6208
81f479b
01ecb47
9b3e2b7
f90516a
cee2d83
da2544c
48e0e2b
7ee9e4f
0e5452d
0a70f45
a2522b0
8cdbd45
6262611
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,33 @@ | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.common.action_chains import ActionChains | ||
| from selenium.webdriver.remote.webelement import WebElement | ||
| from Selenium2Library import utils | ||
| from Selenium2Library.locators import ElementFinder | ||
| from Selenium2Library.locators import CustomLocator | ||
| from keywordgroup import KeywordGroup | ||
|
|
||
| try: | ||
| basestring # attempt to evaluate basestring | ||
| def isstr(s): | ||
| return isinstance(s, basestring) | ||
| except NameError: | ||
| def isstr(s): | ||
| return isinstance(s, str) | ||
|
|
||
| class _ElementKeywords(KeywordGroup): | ||
|
|
||
| def __init__(self): | ||
| self._element_finder = ElementFinder() | ||
|
|
||
| # Public, get element(s) | ||
|
|
||
| def get_webelements(self, locator): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ombre42 and I discussed this over on #315. 'Get Elements' was my original name but changed it because it conflicted with the XML Library's keyword of the same name. So we settled on Get WebElements. I also had a 'Get WebElement' (singular) keyword in there but removed it for some reason. I was doing some recent testing with this and saw a possible need for getting a single web element.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
| """Returns list of WebElement objects matching locator. | ||
|
|
||
| See `introduction` for details about locating elements. | ||
| """ | ||
| return self._element_find(locator, False, True) | ||
|
|
||
| # Public, element lookups | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
| def current_frame_contains(self, text, loglevel='INFO'): | ||
|
|
@@ -638,12 +656,17 @@ def remove_location_strategy(self, strategy_name): | |
|
|
||
| def _element_find(self, locator, first_only, required, tag=None): | ||
| browser = self._current_browser() | ||
| elements = self._element_finder.find(browser, locator, tag) | ||
| if required and len(elements) == 0: | ||
| raise ValueError("Element locator '" + locator + "' did not match any elements.") | ||
| if first_only: | ||
| if len(elements) == 0: return None | ||
| return elements[0] | ||
| if isstr(locator): | ||
| elements = self._element_finder.find(browser, locator, tag) | ||
| if required and len(elements) == 0: | ||
| raise ValueError("Element locator '" + locator + "' did not match any elements.") | ||
| if first_only: | ||
| if len(elements) == 0: return None | ||
| return elements[0] | ||
| elif isinstance(locator, WebElement): | ||
| elements = locator | ||
| # do some other stuff here like deal with list of webelements | ||
| # ... or raise locator/element specific error if required | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything specific that goes here, or is this just a future note?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a future note... |
||
| return elements | ||
|
|
||
| def _frame_contains(self, locator, text): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backticks