Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Selenium2Library/locators/elementfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def __init__(self):
'jquery': self._find_by_sizzle_selector,
'sizzle': self._find_by_sizzle_selector,
'tag': self._find_by_tag_name,
'scLocator': self._find_by_sc_locator,
'default': self._find_by_default
}
self._strategies = NormalizedDict(initial=strategies, caseless=True, spaceless=True)
Expand Down Expand Up @@ -89,6 +90,10 @@ def _find_by_tag_name(self, browser, criteria, tag, constraints):
return self._filter_elements(
browser.find_elements_by_tag_name(criteria),
tag, constraints)

def _find_by_sc_locator(self, browser, criteria, tag, constraints):
js = "return isc.AutoTest.getElement('%s')" % criteria.replace("'", "\\'")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of questions. One, you use a double backslash "" when in all your references I see a double forward slash "//". For example, from here I see

//ListGrid[ID='filterGrid']
 //DynamicForm[ID="autoTestForm"]/item[name=textField||title=textField||value=test||index=0||Class=TextItem]/element 

and from codecentric

//DynamicForm[ID="doSearchForm"]/item[name=mainRegisterBox]/element
//Button[ID="searchPerson"]/
//ListGrid[ID="hitList"].0.0

Second, you also are replacing within the given locator what seems to be a leading single quote. That makes me assume that you are expecting the user to write a locator like these

scLocator='ListGrid[ID='filterGrid']'
scLocator='//ListGrid[ID='filterGrid']'

Again I am not familiar with SmartClient and SmartGWT but the general usage for locators within Selenium2Library has been without the quotes. For example

Good
----
id=my element id
id=this-element

Not-used
--------
id='quoted-string'
id='no used locator'

I know myself I forget this and added quotes ever once in a while. If there is a possibility of having a double space in the locator I can see the need to have the sytax support quoted locators. But again in general that is not how they are used elsewhere.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are just handling single quotation marks embedded in a string using single quotes as the start and termination characters so the JS statement is syntactically OK. jQuery selector is very similar and does the same thing. The double backslash is to escape the backslash which is a special char in Python.
Leaning toothpick syndrome!
Without replace (bad):
return isc.AutoTest.getElement('//ListGrid[ID='filterGrid']')
With replace (good):
return isc.AutoTest.getElement('//ListGrid[ID=\'filterGrid\']')

return self._filter_elements([browser.execute_script(js)], tag, constraints)

def _find_by_default(self, browser, criteria, tag, constraints):
if criteria.startswith('//'):
Expand Down