获取到的css_path前面加上:root,适配新版

This commit is contained in:
g1879 2021-12-21 17:26:20 +08:00
parent 7ec51417ce
commit 6094238f60
2 changed files with 4 additions and 3 deletions

View File

@ -192,7 +192,8 @@ class DriverElement(DrissionElement):
} }
return e(arguments[0]); return e(arguments[0]);
''' '''
return self.run_script(js) res_txt = self.run_script(js)
return f':root{res_txt}' if mode == 'css' else res_txt
# -----------------driver独有属性和方法------------------- # -----------------driver独有属性和方法-------------------
@property @property

View File

@ -158,9 +158,9 @@ class SessionElement(DrissionElement):
brothers = len(ele.eles(f'xpath:./preceding-sibling::{ele.tag}')) brothers = len(ele.eles(f'xpath:./preceding-sibling::{ele.tag}'))
path_str = f'/{ele.tag}[{brothers + 1}]{path_str}' if brothers > 0 else f'/{ele.tag}{path_str}' path_str = f'/{ele.tag}[{brothers + 1}]{path_str}' if brothers > 0 else f'/{ele.tag}{path_str}'
ele = ele.parent ele = ele.parent()
return path_str[1:] if mode == 'css' else path_str return f':root{path_str[1:]}' if mode == 'css' else path_str
# ----------------session独有方法----------------------- # ----------------session独有方法-----------------------
def _make_absolute(self, link) -> str: def _make_absolute(self, link) -> str: