mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
check()增加by_js参数;input()和clear()by_js时触发change;增加set.blocked_urls()
This commit is contained in:
parent
f13681e0df
commit
dcbf970075
@ -201,13 +201,26 @@ class ChromiumElement(DrissionElement):
|
|||||||
|
|
||||||
return self._select
|
return self._select
|
||||||
|
|
||||||
def check(self, uncheck=False):
|
def check(self, uncheck=False, by_js=False):
|
||||||
"""选中或取消选中当前元素
|
"""选中或取消选中当前元素
|
||||||
:param uncheck: 是否取消选中
|
:param uncheck: 是否取消选中
|
||||||
|
:param by_js: 是否用js执行
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
js = 'this.checked=false' if uncheck else 'this.checked=true'
|
is_checked = self.states.is_checked
|
||||||
self.run_js(js)
|
if by_js:
|
||||||
|
js = None
|
||||||
|
if is_checked and uncheck:
|
||||||
|
js = 'this.checked=false'
|
||||||
|
elif not is_checked and not uncheck:
|
||||||
|
js = 'this.checked=true'
|
||||||
|
if js:
|
||||||
|
self.run_js(js)
|
||||||
|
self.run_js('this.dispatchEvent(new Event("change", {bubbles: true}));')
|
||||||
|
|
||||||
|
else:
|
||||||
|
if (is_checked and uncheck) or (not is_checked and not uncheck):
|
||||||
|
self.click()
|
||||||
|
|
||||||
def parent(self, level_or_loc=1, index=1):
|
def parent(self, level_or_loc=1, index=1):
|
||||||
"""返回上面某一级父元素,可指定层数或用查询语法定位
|
"""返回上面某一级父元素,可指定层数或用查询语法定位
|
||||||
@ -598,6 +611,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
if isinstance(vals, (list, tuple)):
|
if isinstance(vals, (list, tuple)):
|
||||||
vals = ''.join([str(i) for i in vals])
|
vals = ''.join([str(i) for i in vals])
|
||||||
self.set.prop('value', str(vals))
|
self.set.prop('value', str(vals))
|
||||||
|
self.run_js('this.dispatchEvent(new Event("change", {bubbles: true}));')
|
||||||
return
|
return
|
||||||
|
|
||||||
if clear and vals not in ('\n', '\ue007'):
|
if clear and vals not in ('\n', '\ue007'):
|
||||||
@ -614,6 +628,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
"""
|
"""
|
||||||
if by_js:
|
if by_js:
|
||||||
self.run_js("this.value='';")
|
self.run_js("this.value='';")
|
||||||
|
self.run_js('this.dispatchEvent(new Event("change", {bubbles: true}));')
|
||||||
return
|
return
|
||||||
|
|
||||||
self._input_focus()
|
self._input_focus()
|
||||||
|
@ -159,7 +159,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
@property
|
@property
|
||||||
def select(self) -> SelectElement: ...
|
def select(self) -> SelectElement: ...
|
||||||
|
|
||||||
def check(self, uncheck: bool = False) -> None: ...
|
def check(self, uncheck: bool = False, by_js: bool = False) -> None: ...
|
||||||
|
|
||||||
def attr(self, attr: str) -> Union[str, None]: ...
|
def attr(self, attr: str) -> Union[str, None]: ...
|
||||||
|
|
||||||
|
@ -145,6 +145,18 @@ class ChromiumBaseSetter(BasePageSetter):
|
|||||||
"""
|
"""
|
||||||
self._page._alert.auto = accept if on_off else None
|
self._page._alert.auto = accept if on_off else None
|
||||||
|
|
||||||
|
def blocked_urls(self, urls):
|
||||||
|
"""设置要忽略的url,传入None时清空已设置的内容。
|
||||||
|
:param urls:
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
if not urls:
|
||||||
|
urls = []
|
||||||
|
if not isinstance(urls, (list, tuple)):
|
||||||
|
raise TypeError('urls需传入list或tuple类型。')
|
||||||
|
self._page.run_cdp('Network.enable')
|
||||||
|
self._page.run_cdp('Network.setBlockedURLs', urls=urls)
|
||||||
|
|
||||||
# --------------即将废弃---------------
|
# --------------即将废弃---------------
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -62,6 +62,8 @@ class ChromiumBaseSetter(BasePageSetter):
|
|||||||
|
|
||||||
def upload_files(self, files: Union[str, list, tuple]) -> None: ...
|
def upload_files(self, files: Union[str, list, tuple]) -> None: ...
|
||||||
|
|
||||||
|
def blocked_urls(self, urls: Optional[list, tuple]) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class TabSetter(ChromiumBaseSetter):
|
class TabSetter(ChromiumBaseSetter):
|
||||||
def __init__(self, page): ...
|
def __init__(self, page): ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user