mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
添加texts属性
This commit is contained in:
parent
ac90820f1e
commit
1d01ddf216
@ -61,6 +61,26 @@ class DriverElement(DrissionElement):
|
|||||||
"""返回元素内所有文本"""
|
"""返回元素内所有文本"""
|
||||||
return unescape(self.attr('innerText')).replace('\xa0', ' ')
|
return unescape(self.attr('innerText')).replace('\xa0', ' ')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def texts(self) -> List[str]:
|
||||||
|
"""返回元素内文本节点列表"""
|
||||||
|
js = '''
|
||||||
|
function e(el) {
|
||||||
|
if (!(el instanceof Element)) return;
|
||||||
|
var texts = new Array();
|
||||||
|
var childs = el.childNodes;
|
||||||
|
|
||||||
|
for(var i = 0; i <childs.length ; i++) {
|
||||||
|
if(childs[i].nodeType === Node.TEXT_NODE){
|
||||||
|
texts.push(childs[i].nodeValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return texts;
|
||||||
|
}
|
||||||
|
return e(arguments[0]);
|
||||||
|
'''
|
||||||
|
return self.run_script(js)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def html(self) -> str:
|
def html(self) -> str:
|
||||||
"""返回元素innerHTML文本"""
|
"""返回元素innerHTML文本"""
|
||||||
@ -73,6 +93,7 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def css_path(self) -> str:
|
def css_path(self) -> str:
|
||||||
|
"""返回当前元素的css路径"""
|
||||||
js = '''
|
js = '''
|
||||||
function e(el) {
|
function e(el) {
|
||||||
if (!(el instanceof Element)) return;
|
if (!(el instanceof Element)) return;
|
||||||
@ -98,6 +119,7 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def xpath(self) -> str:
|
def xpath(self) -> str:
|
||||||
|
"""返回当前元素的xpath路径"""
|
||||||
js = '''
|
js = '''
|
||||||
function e(el) {
|
function e(el) {
|
||||||
if (!(el instanceof Element)) return;
|
if (!(el instanceof Element)) return;
|
||||||
@ -125,12 +147,11 @@ class DriverElement(DrissionElement):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def shadow_root(self):
|
def shadow_root(self):
|
||||||
|
"""返回当前元素的shadow_root元素路径"""
|
||||||
e = self.run_script('return arguments[0].shadowRoot')
|
e = self.run_script('return arguments[0].shadowRoot')
|
||||||
if e:
|
if e:
|
||||||
from .shadow_root_element import ShadowRootElement
|
from .shadow_root_element import ShadowRootElement
|
||||||
return ShadowRootElement(e, self)
|
return ShadowRootElement(e, self)
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user