mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
未完成。修改为用js通过xpath获取元素
This commit is contained in:
parent
9e3f22e47d
commit
0077885ce4
@ -248,7 +248,7 @@ class DriverElement(DrissionElement):
|
|||||||
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}'
|
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:
|
elif loc_or_str[0] == 'css selector':
|
||||||
if loc_or_str[1].lstrip().startswith('>'):
|
if loc_or_str[1].lstrip().startswith('>'):
|
||||||
loc_or_str = loc_or_str[0], f'{self.css_path}{loc_or_str[1]}'
|
loc_or_str = loc_or_str[0], f'{self.css_path}{loc_or_str[1]}'
|
||||||
|
|
||||||
@ -494,15 +494,18 @@ def execute_driver_find(page_or_ele: Union[WebElement, WebDriver],
|
|||||||
mode = mode or 'single'
|
mode = mode or 'single'
|
||||||
if mode not in ['single', 'all']:
|
if mode not in ['single', 'all']:
|
||||||
raise ValueError("Argument mode can only be 'single' or 'all'.")
|
raise ValueError("Argument mode can only be 'single' or 'all'.")
|
||||||
try:
|
if loc[0] == 'xpath':
|
||||||
wait = WebDriverWait(page_or_ele, timeout=timeout)
|
pass
|
||||||
if mode == 'single':
|
else:
|
||||||
return DriverElement(wait.until(ec.presence_of_element_located(loc)))
|
try:
|
||||||
elif mode == 'all':
|
wait = WebDriverWait(page_or_ele, timeout=timeout)
|
||||||
eles = wait.until(ec.presence_of_all_elements_located(loc))
|
if mode == 'single':
|
||||||
return [DriverElement(ele) for ele in eles]
|
return DriverElement(wait.until(ec.presence_of_element_located(loc)))
|
||||||
except:
|
elif mode == 'all':
|
||||||
if show_errmsg:
|
eles = wait.until(ec.presence_of_all_elements_located(loc))
|
||||||
print('Element(s) not found.', loc)
|
return [DriverElement(ele) for ele in eles]
|
||||||
raise
|
except:
|
||||||
return [] if mode == 'all' else None
|
if show_errmsg:
|
||||||
|
print('Element(s) not found.', loc)
|
||||||
|
raise
|
||||||
|
return [] if mode == 'all' else None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user