mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-12 12:25:19 +08:00
更新README
This commit is contained in:
parent
8e869264d2
commit
6e319dad80
28
README.en.md
28
README.en.md
@ -262,11 +262,12 @@ MixPage must receive a Drission object and use its driver or session. If no one
|
||||
Tips: When multi-page objects work together, remember to manually create Drission objects and transfer them to page objects for use. Otherwise, page objects can create their own Drission objects, rendering the information impossible to transmit.
|
||||
|
||||
```python
|
||||
# Automatic creation of Drission objects is recommended only for single page objects
|
||||
page = MixPage()
|
||||
# Ways to create MixPage objects
|
||||
page = MixPage() # Automatic creation of Drission objects is recommended only for single page objects
|
||||
page = MixPage('s') # Quickly create in session mode, automatically create a Drission object
|
||||
|
||||
page = MixPage(drission) # Default driver mode
|
||||
page = MixPage(drission, mode='d', timeout=5) # driver mode, element waiting time 5 seconds (default 10 seconds)
|
||||
page = MixPage(drission) # Created by passing in a Drission object
|
||||
page = MixPage(drission, mode='s', timeout=5) # session mode, waiting time 5 seconds (default 10 seconds)
|
||||
|
||||
# Visit URL
|
||||
page.get(url, **kwargs)
|
||||
@ -299,15 +300,15 @@ Note: The element search timeout is 10 seconds by default, you can also set it a
|
||||
# Find by attribute
|
||||
page.ele('@id:ele_id', timeout = 2) # Find the element with id ele_id and set the waiting time to 2 seconds
|
||||
page.eles('@class:class_name') # Find all elements with class class_name
|
||||
page.eles('@class') # Find all elements with class attribute
|
||||
|
||||
# Search by tag name
|
||||
page.ele('tag:li') # Find the first li element
|
||||
page.eles('tag:li') # Find all li elements
|
||||
|
||||
# Find by location
|
||||
page.ele('@id:ele_id').parent # Parent element
|
||||
page.ele('@id:ele_id').next # Next sibling element
|
||||
page.ele('@id:ele_id').prev # Previous brother element
|
||||
# Search by tag name and attributes
|
||||
page.ele('tag:div@class=div_class') # Find the first div element whose class is div_class
|
||||
page.eles('tag:div@class') # Find all div elements with class attribute
|
||||
|
||||
# Find by text
|
||||
page.ele('search text') # Find elements containing incoming text
|
||||
@ -328,6 +329,11 @@ element = page.ele('@id:ele_id')
|
||||
element.ele('@class:class_name') # Find the first element whose class is ele_class at the lower level of element
|
||||
element.eles('tag:li') # Find all li elements below ele_id
|
||||
|
||||
# Find by location
|
||||
element.parent # Parent element
|
||||
elementnext # Next sibling element
|
||||
element.prev # Previous brother element
|
||||
|
||||
# Tandem search
|
||||
page.ele('@id:ele_id').ele('tag:div').next.ele('some text').eles('tag:a')
|
||||
```
|
||||
@ -675,7 +681,7 @@ print(page.ele('@id:su').text) # Output:百度一下
|
||||
|
||||
## MixPage class
|
||||
|
||||
class **MixPage**(drission: Drission = None, mode:str = 'd', timeout: float = 10)
|
||||
class **MixPage**(drission: Union[Drission, str] = None, mode:str = 'd', timeout: float = 10)
|
||||
|
||||
MixPage encapsulates common functions for page operations and can seamlessly switch between driver and session modes. Cookies are automatically synchronized when switching.
|
||||
The function of obtaining information is common to the two modes, and the function of operating page elements is only available in the d mode. Calling a function unique to a certain mode will automatically switch to that mode.
|
||||
@ -683,9 +689,9 @@ It inherits from DriverPage and SessionPage classes. These functions are impleme
|
||||
|
||||
Parameter Description:
|
||||
|
||||
- drission - Drission objects, if not transmitted will create one
|
||||
- drission - Drission objects, if not transmitted will create one. Quickly configure the corresponding mode when passing in's' or'd'
|
||||
- mode - Mode, optional 'd' or 's', default is 'd'
|
||||
- timeout - Search element time-out time (can also be set separately each time element search)
|
||||
- timeout - Timeout time, driver mode search element time and session mode connection time
|
||||
|
||||
### url
|
||||
|
||||
|
@ -255,11 +255,12 @@ MixPage须接收一个Drission对象并使用其中的driver或session,如没
|
||||
Tips: 多页面对象协同工作时,记得手动创建Drission对象并传递给页面对象使用。否则页面对象会各自创建自己的Drission对象,使信息无法传递。
|
||||
|
||||
```python
|
||||
# 自动创建Drission对象,建议只在单页面对象情况下使用
|
||||
page = MixPage()
|
||||
# 创建MixPage对象的方法
|
||||
page = MixPage() # 自动创建Drission对象,driver模式,建议只在单页面对象情况下使用
|
||||
page = MixPage('s') # 以session模式快速创建,自动创建Drission对象
|
||||
|
||||
page = MixPage(drission) # 默认driver模式
|
||||
page = MixPage(drission, mode='d', timeout=5) # driver模式,元素等待时间5秒(默认10秒)
|
||||
page = MixPage(drission) # 以传入Drission对象创建
|
||||
page = MixPage(drission, mode='s', timeout=5) # session模式,等待时间5秒(默认10秒)
|
||||
|
||||
# 访问URL
|
||||
page.get(url, **kwargs)
|
||||
@ -292,15 +293,15 @@ Tips:调用只属于driver模式的方法,会自动切换到driver模式。
|
||||
# 根据属性查找
|
||||
page.ele('@id:ele_id', timeout = 2) # 查找id为ele_id的元素,设置等待时间2秒
|
||||
page.eles('@class:class_name') # 查找所有class为class_name的元素
|
||||
page.eles('@class') # 查找所有拥有class属性的元素
|
||||
|
||||
# 根据tag name查找
|
||||
page.ele('tag:li') # 查找第一个li元素
|
||||
page.eles('tag:li') # 查找所有li元素
|
||||
|
||||
# 根据位置查找
|
||||
page.ele('@id:ele_id').parent # 父元素
|
||||
page.ele('@id:ele_id').next # 下一个兄弟元素
|
||||
page.ele('@id:ele_id').prev # 上一个兄弟元素
|
||||
# 根据tag name及属性查找
|
||||
page.ele('tag:div@class=div_class') # 查找class为div_class的div元素
|
||||
page.eles('tag:div@class') # 查找所有拥有class属性的div元素
|
||||
|
||||
# 根据文本内容查找
|
||||
page.ele('search text') # 查找包含传入文本的元素
|
||||
@ -321,6 +322,11 @@ element = page.ele('@id:ele_id')
|
||||
element.ele('@class:class_name') # 在element下级查找第一个class为ele_class的元素
|
||||
element.eles('tag:li') # 在ele_id下级查找所有li元素
|
||||
|
||||
# 根据位置查找
|
||||
element.parent # 父元素
|
||||
element.next # 下一个兄弟元素
|
||||
element.prev # 上一个兄弟元素
|
||||
|
||||
# 串连查找
|
||||
page.ele('@id:ele_id').ele('tag:div').next.ele('some text').eles('tag:a')
|
||||
```
|
||||
@ -667,7 +673,7 @@ class **Drission**(driver_options: Union[dict, Options] = None, session_options:
|
||||
|
||||
## MixPage类
|
||||
|
||||
class **MixPage**(drission: Drission = None, mode:str = 'd', timeout: float = 10)
|
||||
class **MixPage**(drission: Union[Drission, str] = None, mode:str = 'd', timeout: float = 10)
|
||||
|
||||
MixPage封装了页面操作的常用功能,可在driver和session模式间无缝切换。切换的时候会自动同步cookies。
|
||||
获取信息功能为两种模式共有,操作页面元素功能只有d模式有。调用某种模式独有的功能,会自动切换到该模式。
|
||||
@ -675,9 +681,9 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
参数说明:
|
||||
|
||||
- drission - Drission对象,如没传入则创建一个
|
||||
- drission - Drission对象,如没传入则创建一个。传入's'或'd'时快速配置相应模式
|
||||
- mode - 模式,可选'd'或's',默认为'd'
|
||||
- timeout - 查找元素超时时间(每次查找元素时还可单独设置)
|
||||
- timeout - 超时时间,driver模式查找元素时间及session模式连接时间
|
||||
|
||||
### url
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user