mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
更新README
This commit is contained in:
parent
cff95304f9
commit
4888614df5
330
README.en.md
330
README.en.md
@ -651,7 +651,7 @@ print(page.ele('@id:su').text) # Output:百度一下
|
||||
|
||||
Return proxy configuration in dictionary format.
|
||||
|
||||
### cookies_to_session
|
||||
### cookies_to_session()
|
||||
|
||||
cookies_to_session(copy_user_agent: bool = False, driver: WebDriver = None, session: Session = None) -> None
|
||||
|
||||
@ -663,7 +663,7 @@ print(page.ele('@id:su').text) # Output:百度一下
|
||||
- driver - WebDriver object, copy cookies
|
||||
- session - Session object, receiving cookies
|
||||
|
||||
### cookies_to_driver
|
||||
### cookies_to_driver()
|
||||
|
||||
cookies_to_driver(url: str, driver: WebDriver = None, session: Session = None) -> None
|
||||
|
||||
@ -675,7 +675,7 @@ print(page.ele('@id:su').text) # Output:百度一下
|
||||
- driver - WebDriver object, receiving cookies
|
||||
- session - Session object, copy cookies
|
||||
|
||||
### user_agent_to_session
|
||||
### user_agent_to_session()
|
||||
|
||||
user_agent_to_session(driver: WebDriver = None, session: Session = None) -> None
|
||||
|
||||
@ -686,19 +686,19 @@ print(page.ele('@id:su').text) # Output:百度一下
|
||||
- driver - WebDriver object, copy user agent
|
||||
- session - Session object, receiving user agent
|
||||
|
||||
### close_driver
|
||||
### close_driver()
|
||||
|
||||
close_driver() -> None
|
||||
|
||||
Close the browser and set the driver to None.
|
||||
|
||||
### close_session
|
||||
### close_session()
|
||||
|
||||
close_session() -> None
|
||||
|
||||
Close the session and set it to None.
|
||||
|
||||
### close
|
||||
### close()
|
||||
|
||||
close() -> None
|
||||
|
||||
@ -756,7 +756,7 @@ Parameter Description:
|
||||
|
||||
Return to the page title text.
|
||||
|
||||
### change_mode
|
||||
### change_mode()
|
||||
|
||||
change_mode(mode: str = None, go: bool = True) -> None
|
||||
|
||||
@ -767,7 +767,7 @@ Parameter Description:
|
||||
- mode - Specify the target mode, 'd' or 's'.
|
||||
- go - Whether to jump to the current url after switching modes
|
||||
|
||||
### get
|
||||
### get()
|
||||
|
||||
get(url: str, go_anyway=False, **kwargs) -> Union[bool, None]
|
||||
|
||||
@ -779,7 +779,7 @@ Parameter Description:
|
||||
- go_anyway - Whether to force a jump. If the target url is the same as the current url, the default is not to jump.
|
||||
- kwargs - Used to access parameters when in session mode.
|
||||
|
||||
### ele
|
||||
### ele()
|
||||
|
||||
ele(loc_or_ele: Union[tuple, str, DriverElement, SessionElement], mode: str = None, timeout: float = None, show_errmsg: bool = False) -> Union[DriverElement, SessionElement]
|
||||
|
||||
@ -796,15 +796,33 @@ Parameter Description:
|
||||
|
||||
Examples:
|
||||
|
||||
- page.ele('@id:ele_id') - Find elements by attributes
|
||||
- page.ele('tag:div') - Find elements by tag name
|
||||
- page.ele('text:some text') - Find elements by text
|
||||
- page.ele('some text') - Find elements by text
|
||||
- page.ele('css:>div') - Find elements by css selector
|
||||
- page.ele('xpath://div') - Find elements by xpath
|
||||
- page.ele((By.ID, 'ele_id')) - Find elements by loc
|
||||
- When the element object is received: Return the element object object
|
||||
|
||||
### eles
|
||||
- Find with loc tuple:
|
||||
|
||||
- ele.ele((By.CLASS_NAME, 'ele_class')) - Return the first element whose class is ele_class in children
|
||||
|
||||
- Find with query string:
|
||||
|
||||
Attributes, tag name and attributes, text, xpath, css selector.
|
||||
|
||||
Among them, @ means attribute, = means exact match,: means fuzzy match, the string is searched by default when there is no control string.
|
||||
|
||||
- page.ele('@class:ele_class') - Return the first class element containing ele_class
|
||||
- page.ele('@name=ele_name') - Return the first element whose name is equal to ele_name
|
||||
- page.ele('@placeholder') - Return the first element with placeholder attribute
|
||||
- page.ele('tag:p') - Return the first <p> element
|
||||
- page.ele('tag:div@class:ele_class') - Return the first class div element with ele_class
|
||||
- page.ele('tag:div@class=ele_class') - Return the first div element whose class is equal to ele_class
|
||||
- page.ele('tag:div@text():some_text') - Returns the first div element whose text contains some_text
|
||||
- page.ele('tag:div@text()=some_text') - Returns the first div element whose text is equal to some_text
|
||||
- page.ele('text:some_text') - Returns the first element whose text contains some_text
|
||||
- page.ele('some_text') - Return the first text element containing some_text (equivalent to the previous line)
|
||||
- page.ele('text=some_text') - Returns the first element whose text is equal to some_text
|
||||
- page.ele('xpath://div[@class="ele_class"]') - Return the first element that matches the xpath
|
||||
- page.ele('css:div.ele_class') - Return the first element that matches the css selector
|
||||
|
||||
### eles()
|
||||
|
||||
eles(loc_or_str: Union[tuple, str], timeout: float = None, show_errmsg: bool = False) -> List[DriverElement]
|
||||
|
||||
@ -816,7 +834,7 @@ Parameter Description:
|
||||
- timeout - Search element timeout time, valid in driver mode
|
||||
- show_errmsg - Whether to throw and display when an exception occurs
|
||||
|
||||
### cookies_to_session
|
||||
### cookies_to_session()
|
||||
|
||||
cookies_to_session(copy_user_agent: bool = False) -> None
|
||||
|
||||
@ -826,7 +844,7 @@ Parameter Description:
|
||||
|
||||
- copy_user_agent - Whether to also copy user agent
|
||||
|
||||
### cookies_to_driver
|
||||
### cookies_to_driver()
|
||||
|
||||
cookies_to_driver(url=None) -> None
|
||||
|
||||
@ -836,7 +854,7 @@ Parameter Description:
|
||||
|
||||
- url - cookie domain or url
|
||||
|
||||
### post
|
||||
### post()
|
||||
|
||||
post(url: str, params: dict = None, data: dict = None, go_anyway: bool = False, **kwargs) -> Union[bool, None]
|
||||
|
||||
@ -850,7 +868,7 @@ Parameter Description:
|
||||
- go_anyway - Whether to force a jump. If the target url is the same as the current url, the default is not to jump.
|
||||
- kwargs - Access parameters such as headers
|
||||
|
||||
### download
|
||||
### download()
|
||||
|
||||
download(file_url: str, goal_path: str = None, rename: str = None, file_exists: str = 'rename', show_msg: bool = False, **kwargs) -> tuple
|
||||
|
||||
@ -867,17 +885,33 @@ Parameter Description:
|
||||
|
||||
|
||||
|
||||
The following methods only take effect in driver mode, and will automatically switch to driver mode when called
|
||||
The following methods and attributes only take effect in driver mode, and will automatically switch to driver mode when called
|
||||
|
||||
***
|
||||
|
||||
### check_page
|
||||
### tabs_count
|
||||
|
||||
Returns the number of tab pages.
|
||||
|
||||
### tab_handles
|
||||
|
||||
Returns the handle list of all tabs.
|
||||
|
||||
### current_tab_num
|
||||
|
||||
Returns the serial number of the current tab page.
|
||||
|
||||
### current_tab_handle
|
||||
|
||||
Returns the handle of the current tab page.
|
||||
|
||||
### check_page()
|
||||
|
||||
check_page() -> bool
|
||||
|
||||
After the subclass is derived, it is used to check whether the domain name meets expectations, and the function is implemented by the subclass.
|
||||
|
||||
### run_script
|
||||
### run_script()
|
||||
|
||||
run_script(script: str) -> Any
|
||||
|
||||
@ -887,19 +921,7 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
|
||||
- script - JavaScript code text
|
||||
|
||||
### get_tabs_sum
|
||||
|
||||
get_tabs_sum() -> int
|
||||
|
||||
Returns the number of browser tabs.
|
||||
|
||||
### get_tab_num
|
||||
|
||||
get_tab_num() -> int
|
||||
|
||||
Returns the serial number of the current tab.
|
||||
|
||||
### create_tab
|
||||
### create_tab()
|
||||
|
||||
create_tab(url: str = '') -> None
|
||||
|
||||
@ -909,33 +931,33 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
|
||||
- url - URL to jump in the new tab page
|
||||
|
||||
### close_current_tab
|
||||
### close_current_tab()
|
||||
|
||||
close_current_tab() -> None
|
||||
|
||||
Close the current tab.
|
||||
|
||||
### close_other_tabs
|
||||
### close_other_tabs()
|
||||
|
||||
close_other_tabs(tab_index: int = None) -> None
|
||||
close_other_tabs(num_or_handle: Union[int, str, None] = None) -> None
|
||||
|
||||
Close the tab page except the serial number.
|
||||
Close tab pages other than the incoming tab page, and keep the current page by default.
|
||||
|
||||
Parameter Description:
|
||||
|
||||
- index - The serial number of the reserved tab, start from 0
|
||||
- num_or_handle - The serial number or handle of the tab to keep, the first serial number is 0, and the last is -1
|
||||
|
||||
### to_tab
|
||||
### to_tab()
|
||||
|
||||
to_tab(index: int = 0) -> None
|
||||
to_tab(num_or_handle: Union[int, str] = 0) -> None
|
||||
|
||||
Jump to a tab page with a serial number.
|
||||
Jump to a tab page.
|
||||
|
||||
Parameter Description:
|
||||
|
||||
- index - The serial number of the target tab, start from 0
|
||||
- num_or_handle - The serial number or handle of the tab to keep, the first serial number is 0, and the last is -1
|
||||
|
||||
### to_iframe
|
||||
### to_iframe()
|
||||
|
||||
to_iframe(self, loc_or_ele: Union[int, str, tuple, WebElement, DriverElement] = 'main') -> None
|
||||
|
||||
@ -954,7 +976,7 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
- to_iframe('main') - Switch to the top level
|
||||
- to_iframe('parent') - Switch to the previous level
|
||||
|
||||
### scroll_to_see
|
||||
### scroll_to_see()
|
||||
|
||||
scroll_to_see(loc_or_ele: Union[str, tuple, WebElement, DriverElement]) -> None
|
||||
|
||||
@ -964,7 +986,7 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
|
||||
- loc_or_ele - The search condition of the iframe element is the same as the search condition of the ele () method.
|
||||
|
||||
### scroll_to
|
||||
### scroll_to()
|
||||
|
||||
scroll_to(mode: str = 'bottom', pixel: int = 300) -> None
|
||||
|
||||
@ -975,19 +997,19 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
- mode - Scrolling direction, top, bottom, rightmost, leftmost, up, down, left, right
|
||||
- pixel - Scrolling pixels
|
||||
|
||||
### refresh
|
||||
### refresh()
|
||||
|
||||
refresh() -> None
|
||||
|
||||
Refresh page.
|
||||
|
||||
### back
|
||||
### back()
|
||||
|
||||
back() -> None
|
||||
|
||||
The page back.
|
||||
|
||||
### set_window_size
|
||||
### set_window_size()
|
||||
|
||||
set_window_size(x: int = None, y: int = None) -> None
|
||||
|
||||
@ -998,7 +1020,7 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
- x - Target width
|
||||
- y - Target height
|
||||
|
||||
### screenshot
|
||||
### screenshot()
|
||||
|
||||
screenshot(path: str, filename: str = None) -> str
|
||||
|
||||
@ -1009,7 +1031,7 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
- path - Screenshot save path, default is the temporary folder specified in the ini file
|
||||
- filename - Screenshot file name, default is page title as file name
|
||||
|
||||
### process_alert
|
||||
### process_alert()
|
||||
|
||||
process_alert(mode: str = 'ok', text: str = None) -> Union[str, None]
|
||||
|
||||
@ -1020,7 +1042,7 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
- mode - 'ok' or 'cancel', if enter another value, the button will not be pressed but the text value will still be returned
|
||||
- text - Text can be entered when processing prompt box
|
||||
|
||||
### chrome_downloading
|
||||
### chrome_downloading()
|
||||
|
||||
chrome_downloading(download_path: str = None) -> list
|
||||
|
||||
@ -1030,13 +1052,13 @@ The following methods only take effect in driver mode, and will automatically sw
|
||||
|
||||
- download_path - Download path, the default is the download path in chrome options configuration
|
||||
|
||||
### close_driver
|
||||
### close_driver()
|
||||
|
||||
close_driver() -> None
|
||||
|
||||
Close the driver and browser, and switch to s mode.
|
||||
|
||||
### close_session
|
||||
### close_session()
|
||||
|
||||
close_session() -> None
|
||||
|
||||
@ -1093,24 +1115,36 @@ Parameter Description:
|
||||
|
||||
Returns the last sibling element object.
|
||||
|
||||
### parents
|
||||
### parents()
|
||||
|
||||
parents(num: int = 1) -> Union[DriverElement, None]
|
||||
|
||||
Returns the Nth-level parent element object.
|
||||
|
||||
### nexts
|
||||
Parameter Description:
|
||||
|
||||
- num - The parent element of the upper level
|
||||
|
||||
### nexts()
|
||||
|
||||
nexts(num: int = 1) -> Union[DriverElement, None]
|
||||
|
||||
Returns the next N sibling element objects.
|
||||
|
||||
### prevs
|
||||
Parameter Description:
|
||||
|
||||
- num - The next few sibling elements
|
||||
|
||||
### prevs()
|
||||
|
||||
prevs(num: int = 1) -> Union[DriverElement, None]
|
||||
|
||||
Return the first N sibling element objects.
|
||||
|
||||
Parameter Description:
|
||||
|
||||
- num - The first few sibling elements
|
||||
|
||||
### size
|
||||
|
||||
Returns the element size as a dictionary.
|
||||
@ -1119,7 +1153,7 @@ Parameter Description:
|
||||
|
||||
Put the element coordinates back in a dictionary.
|
||||
|
||||
### ele
|
||||
### ele()
|
||||
|
||||
ele(loc_or_str: Union[tuple, str], mode: str = None, show_errmsg: bool = False, timeout: float = None) -> Union[DriverElement, List[DriverElement], None]
|
||||
|
||||
@ -1136,15 +1170,31 @@ Parameter Description:
|
||||
|
||||
Examples::
|
||||
|
||||
- element.ele('@id:ele_id') - Find elements by attributes
|
||||
- element.ele('tag:div') - Find elements by tag name
|
||||
- element.ele('text:some text') - Find elements by text
|
||||
- element.ele('some text') - Find elements by text
|
||||
- element.ele('css:>div') - Find elements by css selector
|
||||
- element.ele('xpath://div') - Find elements by xpath
|
||||
- element.ele((By.ID, 'ele_id')) - Find elements by loc
|
||||
- Find with loc tuple:
|
||||
|
||||
### eles
|
||||
- ele.ele((By.CLASS_NAME, 'ele_class')) - Return the first element whose class is ele_class in children
|
||||
|
||||
- Find with query string:
|
||||
|
||||
Attributes, tag name and attributes, text, xpath, css selector.
|
||||
|
||||
Among them, @ means attribute, = means exact match,: means fuzzy match, the string is searched by default when there is no control string.
|
||||
|
||||
- page.ele('@class:ele_class') - Return the first class element containing ele_class
|
||||
- page.ele('@name=ele_name') - Return the first element whose name is equal to ele_name
|
||||
- page.ele('@placeholder') - Return the first element with placeholder attribute
|
||||
- page.ele('tag:p') - Return the first <p> element
|
||||
- page.ele('tag:div@class:ele_class') - Return the first class div element with ele_class
|
||||
- page.ele('tag:div@class=ele_class') - Return the first div element whose class is equal to ele_class
|
||||
- page.ele('tag:div@text():some_text') - Returns the first div element whose text contains some_text
|
||||
- page.ele('tag:div@text()=some_text') - Returns the first div element whose text is equal to some_text
|
||||
- page.ele('text:some_text') - Returns the first element whose text contains some_text
|
||||
- page.ele('some_text') - Return the first text element containing some_text (equivalent to the previous line)
|
||||
- page.ele('text=some_text') - Returns the first element whose text is equal to some_text
|
||||
- page.ele('xpath://div[@class="ele_class"]') - Return the first element that matches the xpath
|
||||
- page.ele('css:div.ele_class') - Return the first element that matches the css selector
|
||||
|
||||
### eles()
|
||||
|
||||
eles(loc_or_str: Union[tuple, str], show_errmsg: bool = False, timeout: float = None) -> List[DriverElement]
|
||||
|
||||
@ -1156,7 +1206,7 @@ Parameter Description:
|
||||
- show_errmsg - Whether to throw and display when an exception occurs
|
||||
- timeout - Find Element Timeout
|
||||
|
||||
### attr
|
||||
### attr()
|
||||
|
||||
attr(attr: str) -> str
|
||||
|
||||
@ -1166,7 +1216,7 @@ Parameter Description:
|
||||
|
||||
- attr - Attribute name
|
||||
|
||||
### click
|
||||
### click()
|
||||
|
||||
click(by_js=None) -> bool
|
||||
|
||||
@ -1176,7 +1226,7 @@ Parameter Description:
|
||||
|
||||
- by_js - Whether to click with js
|
||||
|
||||
### input
|
||||
### input()
|
||||
|
||||
input(value, clear: bool = True) -> bool
|
||||
|
||||
@ -1187,7 +1237,7 @@ Parameter Description:
|
||||
- value - Text value
|
||||
- clear - Whether to clear the text box before entering
|
||||
|
||||
### run_script
|
||||
### run_script()
|
||||
|
||||
run_script(script: str) -> Any
|
||||
|
||||
@ -1197,43 +1247,43 @@ Parameter Description:
|
||||
|
||||
- script - JavaScript text
|
||||
|
||||
### submit
|
||||
### submit()
|
||||
|
||||
submit() -> None
|
||||
|
||||
Submit form.
|
||||
|
||||
### clear
|
||||
### clear()
|
||||
|
||||
clear() -> None
|
||||
|
||||
Clear the text box.
|
||||
|
||||
### is_selected
|
||||
### is_selected()
|
||||
|
||||
is_selected() -> bool
|
||||
|
||||
Whether the element is selected.
|
||||
|
||||
### is_enabled
|
||||
### is_enabled()
|
||||
|
||||
is_enabled() -> bool
|
||||
|
||||
Whether the element is available on the page.
|
||||
|
||||
### is_displayed
|
||||
### is_displayed()
|
||||
|
||||
is_displayed() -> bool
|
||||
|
||||
Whether the element is visible.
|
||||
|
||||
### is_valid
|
||||
### is_valid()
|
||||
|
||||
is_valid() -> bool
|
||||
|
||||
Whether the element is valid. This method is used to determine the situation where the page jump element cannot be used
|
||||
|
||||
### screenshot
|
||||
### screenshot()
|
||||
|
||||
screenshot(path: str, filename: str = None) -> str
|
||||
|
||||
@ -1244,7 +1294,7 @@ Parameter Description:
|
||||
- path - Screenshot save path, default is the temporary folder specified in the ini file
|
||||
- filename - Screenshot file name, default is page title as file name
|
||||
|
||||
### select
|
||||
### select()
|
||||
|
||||
select(text: str) -> bool
|
||||
|
||||
@ -1254,7 +1304,7 @@ Parameter Description:
|
||||
|
||||
- text - Option text
|
||||
|
||||
### set_attr
|
||||
### set_attr()
|
||||
|
||||
set_attr(attr: str, value: str) -> bool
|
||||
|
||||
@ -1265,7 +1315,7 @@ Parameter Description:
|
||||
- attr - parameter name
|
||||
- value - Parameter value
|
||||
|
||||
### drag
|
||||
### drag()
|
||||
|
||||
drag(x: int, y: int, speed: int = 40, shake: bool = True) -> bool
|
||||
|
||||
@ -1278,7 +1328,7 @@ Parameter Description:
|
||||
- speed - Drag speed
|
||||
- shake - Random jitter
|
||||
|
||||
### drag_to
|
||||
### drag_to()
|
||||
|
||||
drag_to(ele_or_loc: Union[tuple, WebElement, DrissionElement], speed: int = 40, shake: bool = True) -> bool:
|
||||
|
||||
@ -1290,7 +1340,7 @@ Parameter Description:
|
||||
- speed - Drag speed
|
||||
- shake - Random jitter
|
||||
|
||||
### hover
|
||||
### hover()
|
||||
|
||||
hover()
|
||||
|
||||
@ -1344,25 +1394,37 @@ Parameter Description:
|
||||
|
||||
Returns the last sibling element object.
|
||||
|
||||
### parents
|
||||
### parents()
|
||||
|
||||
parents(num: int = 1) -> Union[DriverElement, None]
|
||||
parents(num: int = 1) -> Union[SessionElement, None]
|
||||
|
||||
Returns the Nth-level parent element object.
|
||||
|
||||
### nexts
|
||||
Parameter Description:
|
||||
|
||||
nexts(num: int = 1) -> Union[DriverElement, None]
|
||||
- num - The parent element of the upper level
|
||||
|
||||
### nexts()
|
||||
|
||||
nexts(num: int = 1) -> Union[SessionElement, None]
|
||||
|
||||
Returns the next N sibling element objects.
|
||||
|
||||
### prevs
|
||||
Parameter Description:
|
||||
|
||||
prevs(num: int = 1) -> Union[DriverElement, None]
|
||||
- num - The next few sibling elements
|
||||
|
||||
### prevs()
|
||||
|
||||
prevs(num: int = 1) -> Union[SessionElement, None]
|
||||
|
||||
Return the first N sibling element objects.
|
||||
|
||||
### ele
|
||||
Parameter Description:
|
||||
|
||||
- num - The first few sibling elements
|
||||
|
||||
### ele()
|
||||
|
||||
ele(loc_or_str: Union[tuple, str], mode: str = None, show_errmsg: bool = False) -> Union[SessionElement, List[SessionElement], None]
|
||||
|
||||
@ -1380,15 +1442,31 @@ Parameter Description:
|
||||
|
||||
Examples:
|
||||
|
||||
- element.ele('@id:ele_id') - Find elements by attributes
|
||||
- element.ele('tag:div') - Find elements by tag name
|
||||
- element.ele('text:some text') - Find elements by text
|
||||
- element.ele('some text') - Find elements by text
|
||||
- element.ele('css:>div') - Find elements by css selector
|
||||
- element.ele('xpath://div') - Find elements according to xpath
|
||||
- element.ele((By.ID, 'ele_id')) - Find elements according to loc
|
||||
- Find with loc tuple:
|
||||
|
||||
### eles
|
||||
- ele.ele((By.CLASS_NAME, 'ele_class')) - Return the first element whose class is ele_class in children
|
||||
|
||||
- Find with query string:
|
||||
|
||||
Attributes, tag name and attributes, text, xpath, css selector.
|
||||
|
||||
Among them, @ means attribute, = means exact match,: means fuzzy match, the string is searched by default when there is no control string.
|
||||
|
||||
- page.ele('@class:ele_class') - Return the first class element containing ele_class
|
||||
- page.ele('@name=ele_name') - Return the first element whose name is equal to ele_name
|
||||
- page.ele('@placeholder') - Return the first element with placeholder attribute
|
||||
- page.ele('tag:p') - Return the first <p> element
|
||||
- page.ele('tag:div@class:ele_class') - Return the first class div element with ele_class
|
||||
- page.ele('tag:div@class=ele_class') - Return the first div element whose class is equal to ele_class
|
||||
- page.ele('tag:div@text():some_text') - Returns the first div element whose text contains some_text
|
||||
- page.ele('tag:div@text()=some_text') - Returns the first div element whose text is equal to some_text
|
||||
- page.ele('text:some_text') - Returns the first element whose text contains some_text
|
||||
- page.ele('some_text') - Return the first text element containing some_text (equivalent to the previous line)
|
||||
- page.ele('text=some_text') - Returns the first element whose text is equal to some_text
|
||||
- page.ele('xpath://div[@class="ele_class"]') - Return the first element that matches the xpath
|
||||
- page.ele('css:div.ele_class') - Return the first element that matches the css selector
|
||||
|
||||
### eles()
|
||||
|
||||
eles(loc_or_str: Union[tuple, str], show_errmsg: bool = False) -> List[SessionElement]
|
||||
|
||||
@ -1399,7 +1477,7 @@ Parameter Description:
|
||||
- loc_or_str - Query condition parameters
|
||||
- show_errmsg - Whether to throw and display when an exception occurs
|
||||
|
||||
### attr
|
||||
### attr()
|
||||
|
||||
attr(attr: str) -> str
|
||||
|
||||
@ -1421,7 +1499,7 @@ Parameter Description:
|
||||
|
||||
- path - Ini file path, if not imported, the configs.ini file in the current folder is read by default
|
||||
|
||||
### get_value
|
||||
### get_value()
|
||||
|
||||
get_value(section: str, item: str) -> Any
|
||||
|
||||
@ -1432,7 +1510,7 @@ Parameter Description:
|
||||
- section - Paragraph name
|
||||
- item - Configuration item name
|
||||
|
||||
### get_option
|
||||
### get_option()
|
||||
|
||||
get_option(section: str) -> dict
|
||||
|
||||
@ -1442,7 +1520,7 @@ Parameter Description:
|
||||
|
||||
- section - Paragraph name
|
||||
|
||||
### set_item
|
||||
### set_item()
|
||||
|
||||
set_item(section: str, item: str, value: str) -> OptionsManager
|
||||
|
||||
@ -1454,7 +1532,7 @@ Parameter Description:
|
||||
- item - Configuration item name
|
||||
- value - Content of value
|
||||
|
||||
### save
|
||||
### save()
|
||||
|
||||
save(path: str = None) -> OptionsManager
|
||||
|
||||
@ -1484,7 +1562,7 @@ Parameter Description:
|
||||
|
||||
Path of chrome.exe.
|
||||
|
||||
### remove_argument
|
||||
### remove_argument()
|
||||
|
||||
remove_argument(value: str) -> DriverOptions
|
||||
|
||||
@ -1494,7 +1572,7 @@ Parameter Description:
|
||||
|
||||
- value - The attribute value to be removed
|
||||
|
||||
### remove_experimental_option
|
||||
### remove_experimental_option()
|
||||
|
||||
remove_experimental_option(key: str) -> DriverOptions
|
||||
|
||||
@ -1504,13 +1582,13 @@ Parameter Description:
|
||||
|
||||
- key - The key value of the experiment to be removed
|
||||
|
||||
### remove_argument
|
||||
### remove_argument()
|
||||
|
||||
remove_argument() -> DriverOptions
|
||||
|
||||
Remove all plug-ins, because the plug-in is stored in the entire file, it is difficult to remove one of them, so if you need to set, remove all and reset.
|
||||
|
||||
### save
|
||||
### save()
|
||||
|
||||
save(path: str = None) -> DriverOptions
|
||||
|
||||
@ -1520,7 +1598,7 @@ Parameter Description:
|
||||
|
||||
- path - The path of the ini file, which is saved to the module folder by default
|
||||
|
||||
### set_argument
|
||||
### set_argument()
|
||||
|
||||
set_argument(arg: str, value: Union[bool, str]) -> DriverOptions
|
||||
|
||||
@ -1531,7 +1609,7 @@ Parameter Description:
|
||||
- arg - attribute name
|
||||
- value - the attribute value, the attribute with value is passed in the value, the attribute without value is passed in bool
|
||||
|
||||
### set_headless
|
||||
### set_headless()
|
||||
|
||||
set_headless(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1541,7 +1619,7 @@ Parameter Description:
|
||||
|
||||
on_off - open or close, bool
|
||||
|
||||
### set_no_imgs
|
||||
### set_no_imgs()
|
||||
|
||||
set_no_imgs(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1551,7 +1629,7 @@ Parameter Description:
|
||||
|
||||
on_off - open or close, bool
|
||||
|
||||
### set_no_js
|
||||
### set_no_js()
|
||||
|
||||
set_no_js(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1561,7 +1639,7 @@ Parameter Description:
|
||||
|
||||
on_off - open or close, bool
|
||||
|
||||
### set_mute
|
||||
### set_mute()
|
||||
|
||||
set_mute(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1571,7 +1649,7 @@ Parameter Description:
|
||||
|
||||
on_off - open or close, bool
|
||||
|
||||
### set_user_agent
|
||||
### set_user_agent()
|
||||
|
||||
set_user_agent(user_agent: str) -> DriverOptions
|
||||
|
||||
@ -1581,7 +1659,7 @@ Parameter Description:
|
||||
|
||||
- user_agent - user agent string
|
||||
|
||||
### set_proxy
|
||||
### set_proxy()
|
||||
|
||||
set_proxy(proxy: str) -> DriverOptions
|
||||
|
||||
@ -1591,7 +1669,7 @@ Parameter Description:
|
||||
|
||||
- proxy - proxy address
|
||||
|
||||
### set_paths
|
||||
### set_paths()
|
||||
|
||||
set_paths(driver_path: str = None, chrome_path: str = None, debugger_address: str = None, download_path: str = None, user_data_path: str = None, cache_path: str = None) -> DriverOptions
|
||||
|
||||
@ -1612,7 +1690,7 @@ Parameter Description:
|
||||
|
||||
The configuration of chrome is too difficult to remember, so the commonly used configuration is written as a simple method, and the call will modify the relevant content of the ini file.
|
||||
|
||||
### set_paths
|
||||
### set_paths()
|
||||
|
||||
set_paths(driver_path: str = None, chrome_path: str = None, debugger_address: str = None, global_tmp_path: str = None, download_path: str = None, user_data_path: str = None, cache_path: str = None, check_version: bool = True) -> None
|
||||
|
||||
@ -1629,7 +1707,7 @@ Parameter Description:
|
||||
- cache_path - Cache path
|
||||
- check_version - Whether to check whether chromedriver and chrome match
|
||||
|
||||
### set_argument
|
||||
### set_argument()
|
||||
|
||||
set_argument(arg: str, value: Union[bool, str]) -> None
|
||||
|
||||
@ -1640,7 +1718,7 @@ Parameter Description:
|
||||
- arg - Attribute name
|
||||
- value - Attribute value, pass in a value if it has a value, pass in a bool if it doesn't
|
||||
|
||||
### set_headless
|
||||
### set_headless()
|
||||
|
||||
set_headless(on_off: bool) -> None
|
||||
|
||||
@ -1650,7 +1728,7 @@ Parameter Description:
|
||||
|
||||
- on_off - Whether to enable headless mode
|
||||
|
||||
### set_no_imgs
|
||||
### set_no_imgs()
|
||||
|
||||
set_no_imgs(on_off: bool) -> None
|
||||
|
||||
@ -1660,7 +1738,7 @@ Parameter Description:
|
||||
|
||||
- on_off - Whether to enable no-picture mode
|
||||
|
||||
### set_no_js
|
||||
### set_no_js()
|
||||
|
||||
set_no_js(on_off: bool) -> None
|
||||
|
||||
@ -1670,7 +1748,7 @@ Parameter Description:
|
||||
|
||||
- on_off - Whether to enable or disable JS mode
|
||||
|
||||
### set_mute
|
||||
### set_mute()
|
||||
|
||||
set_mute(on_off: bool) -> None
|
||||
|
||||
@ -1680,7 +1758,7 @@ Parameter Description:
|
||||
|
||||
- on_off - Whether to turn on silent mode
|
||||
|
||||
### set_user_agent
|
||||
### set_user_agent()
|
||||
|
||||
set_user_agent(user_agent: str) -> None:
|
||||
|
||||
@ -1690,7 +1768,7 @@ Parameter Description:
|
||||
|
||||
- user_agent - user_agent value
|
||||
|
||||
### set_proxy
|
||||
### set_proxy()
|
||||
|
||||
set_proxy(proxy: str) -> None
|
||||
|
||||
@ -1700,7 +1778,7 @@ Parameter Description:
|
||||
|
||||
- proxy - Proxy value
|
||||
|
||||
### check_driver_version
|
||||
### check_driver_version()
|
||||
|
||||
check_driver_version(driver_path: str = None, chrome_path: str = None) -> bool
|
||||
|
||||
|
346
README.zh-cn.md
346
README.zh-cn.md
@ -636,7 +636,7 @@ class **Drission**(driver_options: Union[dict, Options] = None, session_options:
|
||||
|
||||
### driver
|
||||
|
||||
获取WebDriver对象,调用时自动创建,按传入配置或ini文件配置初始化。
|
||||
返回WebDriver对象,调用时自动创建,按传入配置或ini文件配置初始化。
|
||||
|
||||
### driver_options
|
||||
|
||||
@ -650,7 +650,7 @@ class **Drission**(driver_options: Union[dict, Options] = None, session_options:
|
||||
|
||||
以字典格式返回代理配置。
|
||||
|
||||
### cookies_to_session
|
||||
### cookies_to_session()
|
||||
|
||||
cookies_to_session(copy_user_agent: bool = False, driver: WebDriver = None, session: Session = None) -> None
|
||||
|
||||
@ -662,7 +662,7 @@ class **Drission**(driver_options: Union[dict, Options] = None, session_options:
|
||||
- driver - WebDriver对象,复制cookies
|
||||
- session - Session对象,接收cookies
|
||||
|
||||
### cookies_to_driver
|
||||
### cookies_to_driver()
|
||||
|
||||
cookies_to_driver(url: str, driver: WebDriver = None, session: Session = None) -> None
|
||||
|
||||
@ -674,7 +674,7 @@ class **Drission**(driver_options: Union[dict, Options] = None, session_options:
|
||||
- driver - WebDriver对象,接收cookies
|
||||
- session - Session对象,复制cookies
|
||||
|
||||
### user_agent_to_session
|
||||
### user_agent_to_session()
|
||||
|
||||
user_agent_to_session(driver: WebDriver = None, session: Session = None) -> None
|
||||
|
||||
@ -685,19 +685,19 @@ class **Drission**(driver_options: Union[dict, Options] = None, session_options:
|
||||
- driver - WebDriver对象,复制user agent
|
||||
- session - Session对象,接收user agent
|
||||
|
||||
### close_driver
|
||||
### close_driver()
|
||||
|
||||
close_driver() -> None
|
||||
|
||||
关闭浏览器,driver置为None。
|
||||
|
||||
### close_session
|
||||
### close_session()
|
||||
|
||||
close_session() -> None
|
||||
|
||||
关闭session并置为None。
|
||||
|
||||
### close
|
||||
### close()
|
||||
|
||||
close() -> None
|
||||
|
||||
@ -755,7 +755,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
返回页面title文本。
|
||||
|
||||
### change_mode
|
||||
### change_mode()
|
||||
|
||||
change_mode(mode: str = None, go: bool = True) -> None
|
||||
|
||||
@ -766,7 +766,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- mode - 指定目标模式,'d'或's'。
|
||||
- go - 切换模式后是否跳转到当前url
|
||||
|
||||
### get
|
||||
### get()
|
||||
|
||||
get(url: str, go_anyway=False, **kwargs) -> Union[bool, None]
|
||||
|
||||
@ -778,32 +778,50 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- go_anyway - 是否强制跳转。若目标url和当前url一致,默认不跳转。
|
||||
- kwargs - 用于session模式时访问参数。
|
||||
|
||||
### ele
|
||||
### ele()
|
||||
|
||||
ele(loc_or_ele: Union[tuple, str, DriverElement, SessionElement], mode: str = None, timeout: float = None, show_errmsg: bool = False) -> Union[DriverElement, SessionElement]
|
||||
|
||||
根据查询参数获取元素,返回元素或元素列表。
|
||||
返回页面中符合条件的元素,默认返回第一个。
|
||||
如查询参数是字符串,可选'@属性名:'、'tag:'、'text:'、'css:'、'xpath:'方式。无控制方式时默认用text方式查找。
|
||||
如是loc,直接按照内容查询。
|
||||
|
||||
参数说明:
|
||||
|
||||
- loc_or_str - 查询条件参数,如传入一个元素对象,则直接返回
|
||||
- mode - 查找一个或多个,传入'single'或'all'
|
||||
- loc_or_str - 元素的定位信息,可以是元素对象,loc元组,或查询字符串
|
||||
- mode - 'single' 或 'all‘,对应查找一个或全部
|
||||
- timeout - 查找元素超时时间,driver模式下有效
|
||||
- show_errmsg - 出现异常时是否抛出及显示
|
||||
|
||||
示例:
|
||||
|
||||
- page.ele('@id:ele_id') - 按照属性查找元素
|
||||
- page.ele('tag:div') - 按照tag name查找元素
|
||||
- page.ele('text:some text') - 按照文本查找元素
|
||||
- page.ele('some text') - 按照文本查找元素
|
||||
- page.ele('css:>div') - 按照css selector查找元素
|
||||
- page.ele('xpath://div') - 按照xpath查找元素
|
||||
- page.ele((By.ID, 'ele_id')) - 按照loc方式查找元素
|
||||
- 接收到元素对象时:返回元素对象对象
|
||||
|
||||
### eles
|
||||
- 用loc元组查找:
|
||||
|
||||
- ele.ele((By.CLASS_NAME, 'ele_class')) - 返回第一个class为ele_class的子元素
|
||||
|
||||
- 用查询字符串查找:
|
||||
|
||||
属性、tag name和属性、文本、xpath、css selector。
|
||||
|
||||
其中,@表示属性,=表示精确匹配,:表示模糊匹配,无控制字符串时默认搜索该字符串。
|
||||
|
||||
- page.ele('@class:ele_class') - 返回第一个class含有ele_class的元素
|
||||
- page.ele('@name=ele_name') - 返回第一个name等于ele_name的元素
|
||||
- page.ele('@placeholder') - 返回第一个带placeholder属性的元素
|
||||
- page.ele('tag:p') - 返回第一个<p>元素
|
||||
- page.ele('tag:div@class:ele_class') - 返回第一个class含有ele_class的div元素
|
||||
- page.ele('tag:div@class=ele_class') - 返回第一个class等于ele_class的div元素
|
||||
- page.ele('tag:div@text():some_text') - 返回第一个文本含有some_text的div元素
|
||||
- page.ele('tag:div@text()=some_text') - 返回第一个文本等于some_text的div元素
|
||||
- page.ele('text:some_text') - 返回第一个文本含有some_text的元素
|
||||
- page.ele('some_text') - 返回第一个文本含有some_text的元素(等价于上一行)
|
||||
- page.ele('text=some_text') - 返回第一个文本等于some_text的元素
|
||||
- page.ele('xpath://div[@class="ele_class"]') - 返回第一个符合xpath的元素
|
||||
- page.ele('css:div.ele_class') - 返回第一个符合css selector的元素
|
||||
|
||||
### eles()
|
||||
|
||||
eles(loc_or_str: Union[tuple, str], timeout: float = None, show_errmsg: bool = False) -> List[DriverElement]
|
||||
|
||||
@ -815,7 +833,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- timeout - 查找元素超时时间,driver模式下有效
|
||||
- show_errmsg - 出现异常时是否抛出及显示
|
||||
|
||||
### cookies_to_session
|
||||
### cookies_to_session()
|
||||
|
||||
cookies_to_session(copy_user_agent: bool = False) -> None
|
||||
|
||||
@ -825,7 +843,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
- copy_user_agent - 是否同时复制user agent
|
||||
|
||||
### cookies_to_driver
|
||||
### cookies_to_driver()
|
||||
|
||||
cookies_to_driver(url=None) -> None
|
||||
|
||||
@ -835,7 +853,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
- url - cookies的域或url
|
||||
|
||||
### post
|
||||
### post()
|
||||
|
||||
post(url: str, params: dict = None, data: dict = None, go_anyway: bool = False, **kwargs) -> Union[bool, None]
|
||||
|
||||
@ -849,7 +867,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- go_anyway - 是否强制跳转。若目标url和当前url一致,默认不跳转。
|
||||
- kwargs - headers等访问参数
|
||||
|
||||
### download
|
||||
### download()
|
||||
|
||||
download(file_url: str, goal_path: str = None, rename: str = None, file_exists: str = 'rename', show_msg: bool = False, **kwargs) -> tuple
|
||||
|
||||
@ -866,17 +884,33 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
|
||||
|
||||
以下方法只有driver模式下生效,调用时会自动切换到driver模式
|
||||
以下方法和属性只有driver模式下生效,调用时会自动切换到driver模式
|
||||
|
||||
***
|
||||
|
||||
### check_page
|
||||
### tabs_count
|
||||
|
||||
返回标签页数量。
|
||||
|
||||
### tab_handles
|
||||
|
||||
返回所有标签页handle列表。
|
||||
|
||||
### current_tab_num
|
||||
|
||||
返回当前标签页序号。
|
||||
|
||||
### current_tab_handle
|
||||
|
||||
返回当前标签页handle。
|
||||
|
||||
### check_page()
|
||||
|
||||
check_page() -> bool
|
||||
|
||||
派生子类后用于检查域名是否符合预期,功能由子类实现。
|
||||
|
||||
### run_script
|
||||
### run_script()
|
||||
|
||||
run_script(script: str) -> Any
|
||||
|
||||
@ -886,19 +920,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
- script - JavaScript代码文本
|
||||
|
||||
### get_tabs_sum
|
||||
|
||||
get_tabs_sum() -> int
|
||||
|
||||
返回浏览器标签页数量。
|
||||
|
||||
### get_tab_num
|
||||
|
||||
get_tab_num() -> int
|
||||
|
||||
返回当前标签页序号。
|
||||
|
||||
### create_tab
|
||||
### create_tab()
|
||||
|
||||
create_tab(url: str = '') -> None
|
||||
|
||||
@ -908,33 +930,33 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
- url - 新标签页跳转到的网址
|
||||
|
||||
### close_current_tab
|
||||
### close_current_tab()
|
||||
|
||||
close_current_tab() -> None
|
||||
|
||||
关闭当前标签页。
|
||||
|
||||
### close_other_tabs
|
||||
### close_other_tabs()
|
||||
|
||||
close_other_tabs(tab_index: int = None) -> None
|
||||
close_other_tabs(num_or_handle: Union[int, str, None] = None) -> None
|
||||
|
||||
关闭除序号外的标签页。
|
||||
关闭传入的标签页以外标签页,默认保留当前页。
|
||||
|
||||
参数说明:
|
||||
|
||||
- index - 保留的标签页序号,从0开始计算
|
||||
- num_or_handle - 要保留的标签页序号或handle,序号第一个为0,最后为-1
|
||||
|
||||
### to_tab
|
||||
### to_tab()
|
||||
|
||||
to_tab(index: int = 0) -> None
|
||||
to_tab(num_or_handle: Union[int, str] = 0) -> None
|
||||
|
||||
跳转到某序号的标签页。
|
||||
跳转到标签页。
|
||||
|
||||
参数说明:
|
||||
|
||||
- index - 目标标签页序号,从0开始计算
|
||||
- num_or_handle - 标签页序号或handle字符串,序号第一个为0,最后为-1
|
||||
|
||||
### to_iframe
|
||||
### to_iframe()
|
||||
|
||||
to_iframe(self, loc_or_ele: Union[int, str, tuple, WebElement, DriverElement] = 'main') -> None
|
||||
|
||||
@ -942,7 +964,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
参数说明:
|
||||
|
||||
- loc_or_ele - 查找iframe元素的条件,可接收iframe序号(0开始)、id或name、控制字符串、loc参数、WebElement对象、DriverElement对象,传入'main'跳到最高层,传入'parent'跳到上一层。
|
||||
- loc_or_ele - 查找iframe元素的条件,可接收iframe序号(0开始)、id或name、查询字符串、loc参数、WebElement对象、DriverElement对象,传入'main'跳到最高层,传入'parent'跳到上一层
|
||||
|
||||
示例:
|
||||
- to_iframe('tag:iframe') - 通过传入iframe的查询字符串定位
|
||||
@ -953,7 +975,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- to_iframe('main') - 跳到最高层
|
||||
- to_iframe('parent') - 跳到上一层
|
||||
|
||||
### scroll_to_see
|
||||
### scroll_to_see()
|
||||
|
||||
scroll_to_see(loc_or_ele: Union[str, tuple, WebElement, DriverElement]) -> None
|
||||
|
||||
@ -963,7 +985,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
- loc_or_ele - 查找iframe元素的条件,和ele()方法的查找条件一致。
|
||||
|
||||
### scroll_to
|
||||
### scroll_to()
|
||||
|
||||
scroll_to(mode: str = 'bottom', pixel: int = 300) -> None
|
||||
|
||||
@ -974,19 +996,19 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- mode - 滚动的方向,top、bottom、rightmost、leftmost、up、down、left、right
|
||||
- pixel - 滚动的像素
|
||||
|
||||
### refresh
|
||||
### refresh()
|
||||
|
||||
refresh() -> None
|
||||
|
||||
刷新页面。
|
||||
|
||||
### back
|
||||
### back()
|
||||
|
||||
back() -> None
|
||||
|
||||
页面后退。
|
||||
|
||||
### set_window_size
|
||||
### set_window_size()
|
||||
|
||||
set_window_size(x: int = None, y: int = None) -> None
|
||||
|
||||
@ -997,7 +1019,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- x - 目标宽度
|
||||
- y - 目标高度
|
||||
|
||||
### screenshot
|
||||
### screenshot()
|
||||
|
||||
screenshot(path: str, filename: str = None) -> str
|
||||
|
||||
@ -1008,7 +1030,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- path - 截图保存路径,默认为ini文件中指定的临时文件夹
|
||||
- filename - 截图文件名,默认为页面title为文件名
|
||||
|
||||
### chrome_downloading
|
||||
### chrome_downloading()
|
||||
|
||||
chrome_downloading(download_path: str = None) -> list
|
||||
|
||||
@ -1018,7 +1040,7 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
|
||||
- download_path - 下载路径,默认为chrome options配置中的下载路径
|
||||
|
||||
### process_alert
|
||||
### process_alert()
|
||||
|
||||
process_alert(mode: str = 'ok', text: str = None) -> Union[str, None]
|
||||
|
||||
@ -1029,13 +1051,13 @@ MixPage封装了页面操作的常用功能,可在driver和session模式间无
|
||||
- mode - 'ok' 或 'cancel',若输入其它值,不会按按钮但依然返回文本值
|
||||
- text - 处理prompt提示框时可输入文本
|
||||
|
||||
### close_driver
|
||||
### close_driver()
|
||||
|
||||
close_driver() -> None
|
||||
|
||||
关闭driver及浏览器,切换到s模式。
|
||||
|
||||
### close_session
|
||||
### close_session()
|
||||
|
||||
close_session() -> None
|
||||
|
||||
@ -1092,23 +1114,35 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
返回上一个兄弟元素对象。
|
||||
|
||||
### parents
|
||||
### parents()
|
||||
|
||||
parents(num: int = 1) -> Union[DriverElement, None]
|
||||
|
||||
返回第N层父级元素对象。
|
||||
|
||||
### nexts
|
||||
参数说明:
|
||||
|
||||
- 第几层父元素
|
||||
|
||||
### nexts()
|
||||
|
||||
nexts(num: int = 1) -> Union[DriverElement, None]
|
||||
|
||||
返回下N个兄弟元素对象。
|
||||
返回后面第N个兄弟元素对象。
|
||||
|
||||
### prevs
|
||||
参数说明:
|
||||
|
||||
- 后面第几个兄弟元素
|
||||
|
||||
### prevs()
|
||||
|
||||
prevs(num: int = 1) -> Union[DriverElement, None]
|
||||
|
||||
返回前N个兄弟元素对象。
|
||||
返回前面第N个兄弟元素对象。
|
||||
|
||||
参数说明:
|
||||
|
||||
- 前面第几个兄弟元素
|
||||
|
||||
### size
|
||||
|
||||
@ -1118,7 +1152,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
以字典方式放回元素坐标。
|
||||
|
||||
### ele
|
||||
### ele()
|
||||
|
||||
ele(loc_or_str: Union[tuple, str], mode: str = None, show_errmsg: bool = False, timeout: float = None) -> Union[DriverElement, List[DriverElement], None]
|
||||
|
||||
@ -1135,15 +1169,31 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
示例:
|
||||
|
||||
- element.ele('@id:ele_id') - 按照属性查找元素
|
||||
- element.ele('tag:div') - 按照tag name查找元素
|
||||
- element.ele('text:some text') - 按照文本查找元素
|
||||
- element.ele('some text') - 按照文本查找元素
|
||||
- element.ele('css:>div') - 按照css selector查找元素
|
||||
- element.ele('xpath://div') - 按照xpath查找元素
|
||||
- element.ele((By.ID, 'ele_id')) - 按照loc方式查找元素
|
||||
- 用loc元组查找:
|
||||
|
||||
### eles
|
||||
- ele.ele((By.CLASS_NAME, 'ele_class')) - 返回第一个class为ele_class的子元素
|
||||
|
||||
- 用查询字符串查找:
|
||||
|
||||
属性、tag name和属性、文本、xpath、css selector。
|
||||
|
||||
其中,@表示属性,=表示精确匹配,:表示模糊匹配,无控制字符串时默认搜索该字符串。
|
||||
|
||||
- ele.ele('@class:ele_class') - 返回第一个class含有ele_class的元素
|
||||
- ele.ele('@name=ele_name') - 返回第一个name等于ele_name的元素
|
||||
- ele.ele('@placeholder') - 返回第一个带placeholder属性的元素
|
||||
- ele.ele('tag:p') - 返回第一个<p>元素
|
||||
- ele.ele('tag:div@class:ele_class') - 返回第一个class含有ele_class的div元素
|
||||
- ele.ele('tag:div@class=ele_class') - 返回第一个class等于ele_class的div元素
|
||||
- ele.ele('tag:div@text():some_text') - 返回第一个文本含有some_text的div元素
|
||||
- ele.ele('tag:div@text()=some_text') - 返回第一个文本等于some_text的div元素
|
||||
- ele.ele('text:some_text') - 返回第一个文本含有some_text的元素
|
||||
- ele.ele('some_text') - 返回第一个文本含有some_text的元素(等价于上一行)
|
||||
- ele.ele('text=some_text') - 返回第一个文本等于some_text的元素
|
||||
- ele.ele('xpath://div[@class="ele_class"]') - 返回第一个符合xpath的元素
|
||||
- ele.ele('css:div.ele_class') - 返回第一个符合css selector的元素
|
||||
|
||||
### eles()
|
||||
|
||||
eles(loc_or_str: Union[tuple, str], show_errmsg: bool = False, timeout: float = None) -> List[DriverElement]
|
||||
|
||||
@ -1155,7 +1205,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
- show_errmsg - 出现异常时是否抛出及显示
|
||||
- timeout - 查找元素超时时间
|
||||
|
||||
### attr
|
||||
### attr()
|
||||
|
||||
attr(attr: str) -> str
|
||||
|
||||
@ -1165,7 +1215,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
- attr - 属性名称
|
||||
|
||||
### click
|
||||
### click()
|
||||
|
||||
click(by_js=None) -> bool
|
||||
|
||||
@ -1175,7 +1225,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
- by_js - 是否用js方式点击
|
||||
|
||||
### input
|
||||
### input()
|
||||
|
||||
input(value, clear: bool = True) -> bool
|
||||
|
||||
@ -1186,7 +1236,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
- value - 文本值
|
||||
- clear - 输入前是否清除文本框
|
||||
|
||||
### run_script
|
||||
### run_script()
|
||||
|
||||
run_script(script: str) -> Any
|
||||
|
||||
@ -1196,43 +1246,43 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
- script - JavaScript文本
|
||||
|
||||
### submit
|
||||
### submit()
|
||||
|
||||
submit() -> None
|
||||
|
||||
提交表单。
|
||||
|
||||
### clear
|
||||
### clear()
|
||||
|
||||
clear() -> None
|
||||
|
||||
清空文本框。
|
||||
|
||||
### is_selected
|
||||
### is_selected()
|
||||
|
||||
is_selected() -> bool
|
||||
|
||||
元素是否被选中。
|
||||
|
||||
### is_enabled
|
||||
### is_enabled()
|
||||
|
||||
is_enabled() -> bool
|
||||
|
||||
元素在页面中是否可用。
|
||||
|
||||
### is_displayed
|
||||
### is_displayed()
|
||||
|
||||
is_displayed() -> bool
|
||||
|
||||
元素是否可见。
|
||||
|
||||
### is_valid
|
||||
### is_valid()
|
||||
|
||||
is_valid() -> bool
|
||||
|
||||
元素是否有效。该方法用于判断页面跳转元素不能用的情况
|
||||
|
||||
### screenshot
|
||||
### screenshot()
|
||||
|
||||
screenshot(path: str, filename: str = None) -> str
|
||||
|
||||
@ -1243,7 +1293,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
- path - 截图保存路径,默认为ini文件中指定的临时文件夹
|
||||
- filename - 截图文件名,默认为页面title为文件名
|
||||
|
||||
### select
|
||||
### select()
|
||||
|
||||
select(text: str) -> bool
|
||||
|
||||
@ -1253,7 +1303,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
|
||||
- text - 选项文本
|
||||
|
||||
### set_attr
|
||||
### set_attr()
|
||||
|
||||
set_attr(attr: str, value: str) -> bool
|
||||
|
||||
@ -1264,7 +1314,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
- attr - 参数名
|
||||
- value - 参数值
|
||||
|
||||
### drag
|
||||
### drag()
|
||||
|
||||
drag(x: int, y: int, speed: int = 40, shake: bool = True) -> bool
|
||||
|
||||
@ -1277,7 +1327,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
- speed - 拖拽速度
|
||||
- shake - 是否随机抖动
|
||||
|
||||
### drag_to
|
||||
### drag_to()
|
||||
|
||||
drag_to(ele_or_loc: Union[tuple, WebElement, DrissionElement], speed: int = 40, shake: bool = True) -> bool:
|
||||
|
||||
@ -1289,7 +1339,7 @@ driver模式的元素对象,包装了一个WebElement对象,并封装了常
|
||||
- speed - 拖拽速度
|
||||
- shake - 是否随机抖动
|
||||
|
||||
### hover
|
||||
### hover()
|
||||
|
||||
hover()
|
||||
|
||||
@ -1343,25 +1393,37 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
返回上一个兄弟元素对象。
|
||||
|
||||
### parents
|
||||
### parents()
|
||||
|
||||
parents(num: int = 1) -> Union[DriverElement, None]
|
||||
parents(num: int = 1) -> Union[SessionElement, None]
|
||||
|
||||
返回第N层父级元素对象。
|
||||
|
||||
### nexts
|
||||
参数说明:
|
||||
|
||||
nexts(num: int = 1) -> Union[DriverElement, None]
|
||||
- num - 第几层父元素
|
||||
|
||||
返回下N个兄弟元素对象。
|
||||
### nexts()
|
||||
|
||||
### prevs
|
||||
nexts(num: int = 1) -> Union[SessionElement, None]
|
||||
|
||||
prevs(num: int = 1) -> Union[DriverElement, None]
|
||||
返回后N个兄弟元素对象。
|
||||
|
||||
参数说明:
|
||||
|
||||
- num - 后面第几个兄弟元素
|
||||
|
||||
### prevs()
|
||||
|
||||
prevs(num: int = 1) -> Union[SessionElement, None]
|
||||
|
||||
返回前N个兄弟元素对象。
|
||||
|
||||
### ele
|
||||
参数说明:
|
||||
|
||||
- num - 前面第几个兄弟元素
|
||||
|
||||
### ele()
|
||||
|
||||
ele(loc_or_str: Union[tuple, str], mode: str = None, show_errmsg: bool = False) -> Union[SessionElement, List[SessionElement], None]
|
||||
|
||||
@ -1379,15 +1441,31 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
示例:
|
||||
|
||||
- element.ele('@id:ele_id') - 按照属性查找元素
|
||||
- element.ele('tag:div') - 按照tag name查找元素
|
||||
- element.ele('text:some text') - 按照文本查找元素
|
||||
- element.ele('some text') - 按照文本查找元素
|
||||
- element.ele('css:>div') - 按照css selector查找元素
|
||||
- element.ele('xpath://div') - 按照xpath查找元素
|
||||
- element.ele((By.ID, 'ele_id')) - 按照loc方式查找元素
|
||||
- 用loc元组查找:
|
||||
|
||||
### eles
|
||||
- ele.ele((By.CLASS_NAME, 'ele_class')) - 返回第一个class为ele_class的子元素
|
||||
|
||||
- 用查询字符串查找:
|
||||
|
||||
属性、tag name和属性、文本、xpath、css selector。
|
||||
|
||||
其中,@表示属性,=表示精确匹配,:表示模糊匹配,无控制字符串时默认搜索该字符串。
|
||||
|
||||
- ele.ele('@class:ele_class') - 返回第一个class含有ele_class的元素
|
||||
- ele.ele('@name=ele_name') - 返回第一个name等于ele_name的元素
|
||||
- ele.ele('@placeholder') - 返回第一个带placeholder属性的元素
|
||||
- ele.ele('tag:p') - 返回第一个<p>元素
|
||||
- ele.ele('tag:div@class:ele_class') - 返回第一个class含有ele_class的div元素
|
||||
- ele.ele('tag:div@class=ele_class') - 返回第一个class等于ele_class的div元素
|
||||
- ele.ele('tag:div@text():some_text') - 返回第一个文本含有some_text的div元素
|
||||
- ele.ele('tag:div@text()=some_text') - 返回第一个文本等于some_text的div元素
|
||||
- ele.ele('text:some_text') - 返回第一个文本含有some_text的元素
|
||||
- ele.ele('some_text') - 返回第一个文本含有some_text的元素(等价于上一行)
|
||||
- ele.ele('text=some_text') - 返回第一个文本等于some_text的元素
|
||||
- ele.ele('xpath://div[@class="ele_class"]') - 返回第一个符合xpath的元素
|
||||
- ele.ele('css:div.ele_class') - 返回第一个符合css selector的元素
|
||||
|
||||
### eles()
|
||||
|
||||
eles(loc_or_str: Union[tuple, str], show_errmsg: bool = False) -> List[SessionElement]
|
||||
|
||||
@ -1398,7 +1476,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
- loc_or_str - 查询条件参数
|
||||
- show_errmsg - 出现异常时是否抛出及显示
|
||||
|
||||
### attr
|
||||
### attr()
|
||||
|
||||
attr(attr: str) -> str
|
||||
|
||||
@ -1420,7 +1498,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- path - ini文件路径,不传入则默认读取当前文件夹下的configs.ini文件
|
||||
|
||||
### get_value
|
||||
### get_value()
|
||||
|
||||
get_value(section: str, item: str) -> Any
|
||||
|
||||
@ -1431,7 +1509,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
- section - 段落名称
|
||||
- item - 配置项名称
|
||||
|
||||
### get_option
|
||||
### get_option()
|
||||
|
||||
get_option(section: str) -> dict
|
||||
|
||||
@ -1441,7 +1519,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- section - 段落名称
|
||||
|
||||
### set_item
|
||||
### set_item()
|
||||
|
||||
set_item(section: str, item: str, value: str) -> OptionsManager
|
||||
|
||||
@ -1453,7 +1531,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
- item - 配置项名称
|
||||
- value - 值内容
|
||||
|
||||
### save
|
||||
### save()
|
||||
|
||||
save(path: str = None) -> OptionsManager
|
||||
|
||||
@ -1483,7 +1561,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
chrome.exe的路径
|
||||
|
||||
### remove_argument
|
||||
### remove_argument()
|
||||
|
||||
remove_argument(value: str) -> DriverOptions
|
||||
|
||||
@ -1493,7 +1571,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- value - 要移除的属性值
|
||||
|
||||
### remove_experimental_option
|
||||
### remove_experimental_option()
|
||||
|
||||
remove_experimental_option(key: str) -> DriverOptions
|
||||
|
||||
@ -1503,13 +1581,13 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- key - 要移除的实验设置key值
|
||||
|
||||
### remove_argument
|
||||
### remove_argument()
|
||||
|
||||
remove_argument() -> DriverOptions
|
||||
|
||||
移除所有插件,因插件是以整个文件储存,难以移除其中一个,故如须设置则全部移除再重设。
|
||||
|
||||
### save
|
||||
### save()
|
||||
|
||||
save(path: str = None) -> DriverOptions
|
||||
|
||||
@ -1519,7 +1597,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- path - ini文件的路径,默认保存到模块文件夹下的
|
||||
|
||||
### set_argument
|
||||
### set_argument()
|
||||
|
||||
set_argument(arg: str, value: Union[bool, str]) -> DriverOptions
|
||||
|
||||
@ -1530,7 +1608,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
- arg - 属性名
|
||||
- value - 属性值,有值的属性传入值,没有的传入bool
|
||||
|
||||
### set_headless
|
||||
### set_headless()
|
||||
|
||||
set_headless(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1540,7 +1618,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
on_off - 打开或关闭,bool
|
||||
|
||||
### set_no_imgs
|
||||
### set_no_imgs()
|
||||
|
||||
set_no_imgs(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1550,7 +1628,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
on_off - 打开或关闭,bool
|
||||
|
||||
### set_no_js
|
||||
### set_no_js()
|
||||
|
||||
set_no_js(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1560,7 +1638,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
on_off - 打开或关闭,bool
|
||||
|
||||
### set_mute
|
||||
### set_mute()
|
||||
|
||||
set_mute(on_off: bool = True) -> DriverOptions
|
||||
|
||||
@ -1570,7 +1648,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
on_off - 打开或关闭,bool
|
||||
|
||||
### set_user_agent
|
||||
### set_user_agent()
|
||||
|
||||
set_user_agent(user_agent: str) -> DriverOptions
|
||||
|
||||
@ -1580,7 +1658,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- user_agent - user agent字符串
|
||||
|
||||
### set_proxy
|
||||
### set_proxy()
|
||||
|
||||
set_proxy(proxy: str) -> DriverOptions
|
||||
|
||||
@ -1590,7 +1668,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
- proxy - 代理地址
|
||||
|
||||
### set_paths
|
||||
### set_paths()
|
||||
|
||||
set_paths(driver_path: str = None, chrome_path: str = None, debugger_address: str = None, download_path: str = None, user_data_path: str = None, cache_path: str = None) -> DriverOptions
|
||||
|
||||
@ -1611,7 +1689,7 @@ session模式的元素对象,包装了一个Element对象,并封装了常用
|
||||
|
||||
chrome的配置太难记,所以把常用的配置写成简单的方法,调用会修改ini文件相关内容。
|
||||
|
||||
### set_paths
|
||||
### set_paths()
|
||||
|
||||
set_paths(driver_path: str = None, chrome_path: str = None, debugger_address: str = None, global_tmp_path: str = None, download_path: str = None, user_data_path: str = None, cache_path: str = None, check_version: bool = True) -> None
|
||||
|
||||
@ -1628,7 +1706,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
- cache_path - 缓存路径
|
||||
- check_version - 是否检查chromedriver和chrome是否匹配
|
||||
|
||||
### set_argument
|
||||
### set_argument()
|
||||
|
||||
set_argument(arg: str, value: Union[bool, str]) -> None
|
||||
|
||||
@ -1639,7 +1717,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
- arg - 属性名
|
||||
- value - 属性值,有值的属性传入值,没有的传入bool
|
||||
|
||||
### set_headless
|
||||
### set_headless()
|
||||
|
||||
set_headless(on_off: bool) -> None
|
||||
|
||||
@ -1649,7 +1727,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
|
||||
- on_off - 是否开启headless模式
|
||||
|
||||
### set_no_imgs
|
||||
### set_no_imgs()
|
||||
|
||||
set_no_imgs(on_off: bool) -> None
|
||||
|
||||
@ -1659,7 +1737,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
|
||||
- on_off - 是否开启无图模式
|
||||
|
||||
### set_no_js
|
||||
### set_no_js()
|
||||
|
||||
set_no_js(on_off: bool) -> None
|
||||
|
||||
@ -1669,7 +1747,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
|
||||
- on_off - 是否开启禁用JS模式
|
||||
|
||||
### set_mute
|
||||
### set_mute()
|
||||
|
||||
set_mute(on_off: bool) -> None
|
||||
|
||||
@ -1679,7 +1757,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
|
||||
- on_off - 是否开启静音模式
|
||||
|
||||
### set_user_agent
|
||||
### set_user_agent()
|
||||
|
||||
set_user_agent(user_agent: str) -> None:
|
||||
|
||||
@ -1689,7 +1767,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
|
||||
- user_agent - user_agent值
|
||||
|
||||
### set_proxy
|
||||
### set_proxy()
|
||||
|
||||
set_proxy(proxy: str) -> None
|
||||
|
||||
@ -1699,7 +1777,7 @@ chrome的配置太难记,所以把常用的配置写成简单的方法,调
|
||||
|
||||
- proxy - 代理值
|
||||
|
||||
### check_driver_version
|
||||
### check_driver_version()
|
||||
|
||||
check_driver_version(driver_path: str = None, chrome_path: str = None) -> bool
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user