mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
优化css_path
This commit is contained in:
parent
25dd981b25
commit
8d1d3b554d
@ -647,7 +647,8 @@ class ChromiumElement(DrissionElement):
|
||||
txt1 = '''
|
||||
let i = el.getAttribute("id");
|
||||
if (i){path = '>' + el.tagName.toLowerCase() + "#" + i + path;
|
||||
break;}
|
||||
el = el.parentNode;
|
||||
continue;}
|
||||
'''
|
||||
txt3 = ''
|
||||
txt4 = '''path = '>' + el.tagName.toLowerCase() + ":nth-child(" + nth + ")" + path;'''
|
||||
@ -655,7 +656,6 @@ class ChromiumElement(DrissionElement):
|
||||
|
||||
js = '''function(){
|
||||
function e(el) {
|
||||
//return el;
|
||||
if (!(el instanceof Element)) return;
|
||||
let path = '';
|
||||
while (el.nodeType === Node.ELEMENT_NODE) {
|
||||
|
@ -149,19 +149,20 @@ class SessionElement(DrissionElement):
|
||||
path_str = ''
|
||||
ele = self
|
||||
|
||||
while ele:
|
||||
if xpath:
|
||||
if xpath:
|
||||
while ele:
|
||||
brothers = len(ele.eles(f'xpath:./preceding-sibling::{ele.tag}'))
|
||||
path_str = f'/{ele.tag}[{brothers + 1}]{path_str}'
|
||||
else:
|
||||
ele = ele.parent()
|
||||
|
||||
else:
|
||||
while ele:
|
||||
id_ = ele.attr('id')
|
||||
if id_:
|
||||
path_str = f'>{ele.tag}#{id_}{path_str}'
|
||||
break
|
||||
brothers = len(ele.eles(f'xpath:./preceding-sibling::*'))
|
||||
path_str = f'>{ele.tag}:nth-child({brothers + 1}){path_str}'
|
||||
|
||||
ele = ele.parent()
|
||||
else:
|
||||
path_str = f'>{ele.tag}:nth-child({len(ele.eles("xpath:./preceding-sibling::*")) + 1}){path_str}'
|
||||
ele = ele.parent()
|
||||
|
||||
return path_str if xpath else f'{path_str[1:]}'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user