mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
Pre Merge pull request !30 from 又阳月/dev
This commit is contained in:
commit
04a2be0b9d
@ -80,7 +80,7 @@ class ChromiumElement(DrissionElement):
|
|||||||
def __call__(self, loc_or_str, timeout=None):
|
def __call__(self, loc_or_str, timeout=None):
|
||||||
"""在内部查找元素
|
"""在内部查找元素
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间(秒)
|
||||||
:return: ChromiumElement对象或属性、文本
|
:return: ChromiumElement对象或属性、文本
|
||||||
"""
|
"""
|
||||||
return self.ele(loc_or_str, timeout)
|
return self.ele(loc_or_str, timeout)
|
||||||
@ -1336,10 +1336,13 @@ def run_js(page_or_ele, script, as_expr=False, timeout=None, args=None):
|
|||||||
:param page_or_ele: 页面对象或元素对象
|
:param page_or_ele: 页面对象或元素对象
|
||||||
:param script: js文本
|
:param script: js文本
|
||||||
:param as_expr: 是否作为表达式运行,为True时args无效
|
:param as_expr: 是否作为表达式运行,为True时args无效
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间(秒)
|
||||||
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
||||||
:return: js执行结果
|
:return: js执行结果
|
||||||
"""
|
"""
|
||||||
|
# 将timeout转换为毫秒
|
||||||
|
if timeout is not None:
|
||||||
|
timeout *= 1000
|
||||||
if isinstance(page_or_ele, (ChromiumElement, ShadowRoot)):
|
if isinstance(page_or_ele, (ChromiumElement, ShadowRoot)):
|
||||||
is_page = False
|
is_page = False
|
||||||
page = page_or_ele.page
|
page = page_or_ele.page
|
||||||
|
@ -38,7 +38,7 @@ class ChromiumBase(BasePage):
|
|||||||
"""
|
"""
|
||||||
:param address: 浏览器 ip:port
|
:param address: 浏览器 ip:port
|
||||||
:param tab_id: 要控制的标签页id,不指定默认为激活的
|
:param tab_id: 要控制的标签页id,不指定默认为激活的
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间(秒)
|
||||||
"""
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._is_loading = None
|
self._is_loading = None
|
||||||
@ -147,7 +147,7 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def _get_document(self, timeout=10):
|
def _get_document(self, timeout=10):
|
||||||
"""获取页面文档
|
"""获取页面文档
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间(秒)
|
||||||
:return: 是否获取成功
|
:return: 是否获取成功
|
||||||
"""
|
"""
|
||||||
if self._debug:
|
if self._debug:
|
||||||
@ -282,7 +282,7 @@ class ChromiumBase(BasePage):
|
|||||||
"""在内部查找元素
|
"""在内部查找元素
|
||||||
例:ele = page('@id=ele_id')
|
例:ele = page('@id=ele_id')
|
||||||
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
:param loc_or_str: 元素的定位信息,可以是loc元组,或查询字符串
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间(秒)
|
||||||
:return: ChromiumElement对象
|
:return: ChromiumElement对象
|
||||||
"""
|
"""
|
||||||
return self.ele(loc_or_str, timeout)
|
return self.ele(loc_or_str, timeout)
|
||||||
@ -468,7 +468,7 @@ class ChromiumBase(BasePage):
|
|||||||
:param script: js文本
|
:param script: js文本
|
||||||
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
||||||
:param as_expr: 是否作为表达式运行,为True时args无效
|
:param as_expr: 是否作为表达式运行,为True时args无效
|
||||||
:param timeout: js超时时间,为None则使用页面timeouts.script设置
|
:param timeout: js超时时间,为None则使用页面timeouts.script设置(秒)
|
||||||
:return: 运行的结果
|
:return: 运行的结果
|
||||||
"""
|
"""
|
||||||
return run_js(self, script, as_expr, self.timeouts.script if timeout is None else timeout, args)
|
return run_js(self, script, as_expr, self.timeouts.script if timeout is None else timeout, args)
|
||||||
@ -478,7 +478,7 @@ class ChromiumBase(BasePage):
|
|||||||
:param script: js文本
|
:param script: js文本
|
||||||
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
||||||
:param as_expr: 是否作为表达式运行,为True时args无效
|
:param as_expr: 是否作为表达式运行,为True时args无效
|
||||||
:param timeout: js超时时间,为None则使用页面timeouts.script设置
|
:param timeout: js超时时间,为None则使用页面timeouts.script设置(秒)
|
||||||
:return: 运行的结果
|
:return: 运行的结果
|
||||||
"""
|
"""
|
||||||
self.wait.load_complete()
|
self.wait.load_complete()
|
||||||
@ -489,23 +489,23 @@ class ChromiumBase(BasePage):
|
|||||||
:param script: js文本
|
:param script: js文本
|
||||||
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
:param args: 参数,按顺序在js文本中对应arguments[0]、arguments[1]...
|
||||||
:param as_expr: 是否作为表达式运行,为True时args无效
|
:param as_expr: 是否作为表达式运行,为True时args无效
|
||||||
:param timeout: js超时时间,为None则使用页面timeouts.script设置
|
:param timeout: js超时时间,为None则使用页面timeouts.script设置(秒)
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
Thread(target=run_js, args=(self, script, as_expr, self.timeouts.script if timeout is None else timeout,
|
Thread(target=run_js, args=(self, script, as_expr, self.timeouts.script if timeout is None else timeout,
|
||||||
args)).start()
|
args)).start()
|
||||||
|
|
||||||
def get(self, url, show_errmsg=False, retry=None, interval=None, timeout=None):
|
def get(self, url='', show_errmsg=False, retry=None, interval=None, timeout=None):
|
||||||
"""访问url
|
"""访问url
|
||||||
:param url: 目标url
|
:param url: 目标url
|
||||||
:param show_errmsg: 是否显示和抛出异常
|
:param show_errmsg: 是否显示和抛出异常
|
||||||
:param retry: 重试次数
|
:param retry: 重试次数
|
||||||
:param interval: 重试间隔(秒)
|
:param interval: 重试间隔(秒)
|
||||||
:param timeout: 连接超时时间
|
:param timeout: 连接超时时间(秒)
|
||||||
:return: 目标url是否可用
|
:return: 目标url是否可用
|
||||||
"""
|
"""
|
||||||
retry, interval = self._before_connect(url, retry, interval)
|
retry, interval = self._process_connection(url, retry, interval)
|
||||||
self._url_available = self._d_connect(self._url, times=retry, interval=interval,
|
self._url_available = self._d_connect(self._url, times=retry, interval=interval,
|
||||||
show_errmsg=show_errmsg, timeout=timeout)
|
show_errmsg=show_errmsg, timeout=timeout)
|
||||||
return self._url_available
|
return self._url_available
|
||||||
@ -531,7 +531,7 @@ class ChromiumBase(BasePage):
|
|||||||
def ele(self, loc_or_ele, timeout=None):
|
def ele(self, loc_or_ele, timeout=None):
|
||||||
"""获取第一个符合条件的元素对象
|
"""获取第一个符合条件的元素对象
|
||||||
:param loc_or_ele: 定位符或元素对象
|
:param loc_or_ele: 定位符或元素对象
|
||||||
:param timeout: 查找超时时间
|
:param timeout: 查找超时时间(秒)
|
||||||
:return: ChromiumElement对象
|
:return: ChromiumElement对象
|
||||||
"""
|
"""
|
||||||
return self._ele(loc_or_ele, timeout=timeout, method='ele()')
|
return self._ele(loc_or_ele, timeout=timeout, method='ele()')
|
||||||
@ -539,7 +539,7 @@ class ChromiumBase(BasePage):
|
|||||||
def eles(self, loc_or_str, timeout=None):
|
def eles(self, loc_or_str, timeout=None):
|
||||||
"""获取所有符合条件的元素对象
|
"""获取所有符合条件的元素对象
|
||||||
:param loc_or_str: 定位符或元素对象
|
:param loc_or_str: 定位符或元素对象
|
||||||
:param timeout: 查找超时时间
|
:param timeout: 查找超时时间(秒)
|
||||||
:return: ChromiumElement对象组成的列表
|
:return: ChromiumElement对象组成的列表
|
||||||
"""
|
"""
|
||||||
return self._ele(loc_or_str, timeout=timeout, single=False)
|
return self._ele(loc_or_str, timeout=timeout, single=False)
|
||||||
@ -568,7 +568,7 @@ class ChromiumBase(BasePage):
|
|||||||
def _find_elements(self, loc_or_ele, timeout=None, single=True, relative=False, raise_err=None):
|
def _find_elements(self, loc_or_ele, timeout=None, single=True, relative=False, raise_err=None):
|
||||||
"""执行元素查找
|
"""执行元素查找
|
||||||
:param loc_or_ele: 定位符或元素对象
|
:param loc_or_ele: 定位符或元素对象
|
||||||
:param timeout: 查找超时时间
|
:param timeout: 查找超时时间(秒)
|
||||||
:param single: 是否只返回第一个
|
:param single: 是否只返回第一个
|
||||||
:param relative: WebPage用的表示是否相对定位的参数
|
:param relative: WebPage用的表示是否相对定位的参数
|
||||||
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
:param raise_err: 找不到元素是是否抛出异常,为None时根据全局设置
|
||||||
@ -712,7 +712,7 @@ class ChromiumBase(BasePage):
|
|||||||
def get_frame(self, loc_ind_ele, timeout=None):
|
def get_frame(self, loc_ind_ele, timeout=None):
|
||||||
"""获取页面中一个frame对象,可传入定位符、iframe序号、ChromiumFrame对象,序号从1开始
|
"""获取页面中一个frame对象,可传入定位符、iframe序号、ChromiumFrame对象,序号从1开始
|
||||||
:param loc_ind_ele: 定位符、iframe序号、ChromiumFrame对象
|
:param loc_ind_ele: 定位符、iframe序号、ChromiumFrame对象
|
||||||
:param timeout: 查找元素超时时间
|
:param timeout: 查找元素超时时间(秒)
|
||||||
:return: ChromiumFrame对象
|
:return: ChromiumFrame对象
|
||||||
"""
|
"""
|
||||||
if isinstance(loc_ind_ele, str):
|
if isinstance(loc_ind_ele, str):
|
||||||
@ -752,7 +752,7 @@ class ChromiumBase(BasePage):
|
|||||||
def get_frames(self, loc=None, timeout=None):
|
def get_frames(self, loc=None, timeout=None):
|
||||||
"""获取所有符合条件的frame对象
|
"""获取所有符合条件的frame对象
|
||||||
:param loc: 定位符,为None时返回所有
|
:param loc: 定位符,为None时返回所有
|
||||||
:param timeout: 查找超时时间
|
:param timeout: 查找超时时间(秒)
|
||||||
:return: ChromiumFrame对象组成的列表
|
:return: ChromiumFrame对象组成的列表
|
||||||
"""
|
"""
|
||||||
loc = loc or 'xpath://*[name()="iframe" or name()="frame"]'
|
loc = loc or 'xpath://*[name()="iframe" or name()="frame"]'
|
||||||
@ -849,7 +849,7 @@ class ChromiumBase(BasePage):
|
|||||||
"""处理提示框,可以自动等待提示框出现
|
"""处理提示框,可以自动等待提示框出现
|
||||||
:param accept: True表示确认,False表示取消,其它值不会按按钮但依然返回文本值
|
:param accept: True表示确认,False表示取消,其它值不会按按钮但依然返回文本值
|
||||||
:param send: 处理prompt提示框时可输入文本
|
:param send: 处理prompt提示框时可输入文本
|
||||||
:param timeout: 等待提示框出现的超时时间,为None则使用self.timeout属性的值
|
:param timeout: 等待提示框出现的超时时间,为None则使用self.timeout属性的值(秒)
|
||||||
:param next_one: 是否处理下一个出现的提示框,为True时timeout参数无效
|
:param next_one: 是否处理下一个出现的提示框,为True时timeout参数无效
|
||||||
:return: 提示框内容文本,未等到提示框则返回False
|
:return: 提示框内容文本,未等到提示框则返回False
|
||||||
"""
|
"""
|
||||||
@ -901,7 +901,7 @@ class ChromiumBase(BasePage):
|
|||||||
|
|
||||||
def _wait_loaded(self, timeout=None):
|
def _wait_loaded(self, timeout=None):
|
||||||
"""等待页面加载完成,超时触发停止加载
|
"""等待页面加载完成,超时触发停止加载
|
||||||
:param timeout: 超时时间
|
:param timeout: 超时时间(秒)
|
||||||
:return: 是否成功,超时返回False
|
:return: 是否成功,超时返回False
|
||||||
"""
|
"""
|
||||||
if self._load_mode == 'none':
|
if self._load_mode == 'none':
|
||||||
@ -924,7 +924,7 @@ class ChromiumBase(BasePage):
|
|||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _before_connect(self, url, retry, interval):
|
def _process_connection(self, url, retry, interval):
|
||||||
"""连接前的准备
|
"""连接前的准备
|
||||||
:param url: 要访问的url
|
:param url: 要访问的url
|
||||||
:param retry: 重试次数
|
:param retry: 重试次数
|
||||||
@ -948,7 +948,7 @@ class ChromiumBase(BasePage):
|
|||||||
:param times: 重试次数
|
:param times: 重试次数
|
||||||
:param interval: 重试间隔(秒)
|
:param interval: 重试间隔(秒)
|
||||||
:param show_errmsg: 是否抛出异常
|
:param show_errmsg: 是否抛出异常
|
||||||
:param timeout: 连接超时时间
|
:param timeout: 连接超时时间(秒)
|
||||||
:return: 是否成功,返回None表示不确定
|
:return: 是否成功,返回None表示不确定
|
||||||
"""
|
"""
|
||||||
err = None
|
err = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user