mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
用xpath查找元素时自动补全//
This commit is contained in:
parent
5f83e93a52
commit
e66f6adc79
@ -213,7 +213,8 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
if loc_or_str[0] == 'xpath':
|
if loc_or_str[0] == 'xpath':
|
||||||
# 确保查询语句最前面是.
|
# 确保查询语句最前面是.
|
||||||
loc_str = f'.{loc_or_str[1]}' if not loc_or_str[1].startswith('.') else loc_or_str[1]
|
loc_str = loc_or_str[1] if loc_or_str[1].startswith(('.', '/')) else f'.//{loc_or_str[1]}'
|
||||||
|
loc_str = loc_str if loc_str.startswith('.') else f'.{loc_str}'
|
||||||
loc_or_str = loc_or_str[0], loc_str
|
loc_or_str = loc_or_str[0], loc_str
|
||||||
else:
|
else:
|
||||||
if loc_or_str[1].lstrip().startswith('>'):
|
if loc_or_str[1].lstrip().startswith('>'):
|
||||||
|
@ -112,8 +112,11 @@ class DriverPage(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(loc_or_ele, str):
|
if isinstance(loc_or_ele, str):
|
||||||
loc_or_ele = get_loc_from_str(loc_or_ele)
|
loc_or_ele = get_loc_from_str(loc_or_ele)
|
||||||
|
if loc_or_ele[0] == 'xpath' and not loc_or_ele[1].startswith('/'):
|
||||||
|
loc_or_ele = 'xpath', f'//{loc_or_ele[1]}'
|
||||||
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
|
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
|
||||||
pass
|
if loc_or_ele[0] == 'xpath' and not loc_or_ele[1].startswith('/'):
|
||||||
|
loc_or_ele = 'xpath', f'//{loc_or_ele[1]}'
|
||||||
elif isinstance(loc_or_ele, DriverElement):
|
elif isinstance(loc_or_ele, DriverElement):
|
||||||
return loc_or_ele
|
return loc_or_ele
|
||||||
elif isinstance(loc_or_ele, WebElement):
|
elif isinstance(loc_or_ele, WebElement):
|
||||||
|
@ -148,9 +148,10 @@ class SessionElement(DrissionElement):
|
|||||||
|
|
||||||
loc_str = None
|
loc_str = None
|
||||||
if loc_or_str[0] == 'xpath':
|
if loc_or_str[0] == 'xpath':
|
||||||
# Element的html是包含自己的,要如下处理,使其只检索下级的
|
loc_str = loc_or_str[1] if loc_or_str[1].startswith(('.', '/')) else f'.//{loc_or_str[1]}'
|
||||||
loc_str = loc_or_str[1] if loc_or_str[1].startswith('.') else f'.{loc_or_str[1]}'
|
loc_str = loc_str if loc_str.startswith('.') else f'.{loc_str}'
|
||||||
elif loc_or_str[0] == 'css selector':
|
elif loc_or_str[0] == 'css selector':
|
||||||
|
# Element的html是包含自己的,要如下处理,使其只检索下级的
|
||||||
loc_str = loc_or_str[1] if loc_or_str[1][0] in '>, ' else f' {loc_or_str[1]}'
|
loc_str = loc_or_str[1] if loc_or_str[1][0] in '>, ' else f' {loc_or_str[1]}'
|
||||||
loc_str = f':root>{self.tag}{loc_str}'
|
loc_str = f':root>{self.tag}{loc_str}'
|
||||||
loc_or_str = loc_or_str[0], loc_str
|
loc_or_str = loc_or_str[0], loc_str
|
||||||
|
@ -99,8 +99,12 @@ class SessionPage(object):
|
|||||||
"""
|
"""
|
||||||
if isinstance(loc_or_ele, str):
|
if isinstance(loc_or_ele, str):
|
||||||
loc_or_ele = get_loc_from_str(loc_or_ele)
|
loc_or_ele = get_loc_from_str(loc_or_ele)
|
||||||
|
if loc_or_ele[0] == 'xpath' and not loc_or_ele[1].startswith('/'):
|
||||||
|
loc_or_ele = 'xpath', f'//{loc_or_ele[1]}'
|
||||||
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
|
elif isinstance(loc_or_ele, tuple) and len(loc_or_ele) == 2:
|
||||||
loc_or_ele = translate_loc_to_xpath(loc_or_ele)
|
loc_or_ele = translate_loc_to_xpath(loc_or_ele)
|
||||||
|
if loc_or_ele[0] == 'xpath' and not loc_or_ele[1].startswith('/'):
|
||||||
|
loc_or_ele = 'xpath', f'//{loc_or_ele[1]}'
|
||||||
elif isinstance(loc_or_ele, SessionElement):
|
elif isinstance(loc_or_ele, SessionElement):
|
||||||
return loc_or_ele
|
return loc_or_ele
|
||||||
elif isinstance(loc_or_ele, Element):
|
elif isinstance(loc_or_ele, Element):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user