未完成。修改为用js通过xpath获取元素

This commit is contained in:
g1879 2020-10-30 12:45:56 +08:00
parent 9e3f22e47d
commit 0077885ce4

View File

@ -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_str if loc_str.startswith('.') else f'.{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('>'):
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'
if mode not in ['single', 'all']:
raise ValueError("Argument mode can only be 'single' or 'all'.")
try:
wait = WebDriverWait(page_or_ele, timeout=timeout)
if mode == 'single':
return DriverElement(wait.until(ec.presence_of_element_located(loc)))
elif mode == 'all':
eles = wait.until(ec.presence_of_all_elements_located(loc))
return [DriverElement(ele) for ele in eles]
except:
if show_errmsg:
print('Element(s) not found.', loc)
raise
return [] if mode == 'all' else None
if loc[0] == 'xpath':
pass
else:
try:
wait = WebDriverWait(page_or_ele, timeout=timeout)
if mode == 'single':
return DriverElement(wait.until(ec.presence_of_element_located(loc)))
elif mode == 'all':
eles = wait.until(ec.presence_of_all_elements_located(loc))
return [DriverElement(ele) for ele in eles]
except:
if show_errmsg:
print('Element(s) not found.', loc)
raise
return [] if mode == 'all' else None