Skip to content

Commit 10d8c50

Browse files
committed
add byclause for searching lists, fixes #3
1 parent e9730a5 commit 10d8c50

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

ngSe/by.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,32 @@ def _table_path_convert(path):
172172
tp=table_path, rt=row_type, r=row, ct=column_type, c=column, cp=cell_path)
173173

174174

175+
def _list_path_convert(path):
176+
# Contract
177+
must_be(path, "path", basestring)
178+
#
179+
parts = path.split('\\')
180+
if len(parts) < 2:
181+
raise ValueError("path value must be: list_path\\[item_type:]item[\\item_path]")
182+
183+
list_path = parts.pop()
184+
185+
item = parts.pop()
186+
item_type = "li"
187+
data = item.split(":")
188+
if len(data) == 1:
189+
item = int(item)
190+
else:
191+
item_type = data[0]
192+
item = int(data[1])
193+
194+
item_path = ""
195+
if len(parts) >= 1:
196+
item_path = "/" + parts.pop()
197+
198+
return '{lp}/{it}[{i}]{ip}'.format(lp=list_path, it=item_type, i=item, ip=item_path)
199+
200+
175201
# Implement the class, add existing values
176202
By = ByDict()
177203
# Is this the best way to do this? Allow retrieving key: None = value: None (for simplifying step parsing)
@@ -182,6 +208,7 @@ def _table_path_convert(path):
182208

183209
By.INNER_TEXT = ByClause(selenium_by.XPATH, _inner_text_convert)
184210
By.TABLE_PATH = ByClause(selenium_by.XPATH, _table_path_convert)
211+
By.LIST_PATH = ByClause(selenium_by.XPATH, _list_path_convert)
185212
By.NG_CLICK = ByClause(selenium_by.CSS_SELECTOR, lambda v: '[ng-click="{}"]'.format(v))
186213
By.VISIBLE_CLICK = ByClause(selenium_by.CSS_SELECTOR, lambda v: '[ng-click="{}"]:not(.ng-hide)'.format(v))
187214
By.NG_MODEL = ByClause(selenium_by.CSS_SELECTOR, lambda v: '[ng-model="{}"]'.format(v))

0 commit comments

Comments
 (0)