mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
添加处理提示框函数
This commit is contained in:
parent
c39be7b17f
commit
2834cc8ca3
@ -8,6 +8,7 @@ from glob import glob
|
|||||||
from typing import Union, List, Any
|
from typing import Union, List, Any
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
|
||||||
|
from selenium.common.exceptions import NoAlertPresentException
|
||||||
from selenium.webdriver.chrome.webdriver import WebDriver
|
from selenium.webdriver.chrome.webdriver import WebDriver
|
||||||
from selenium.webdriver.remote.webelement import WebElement
|
from selenium.webdriver.remote.webelement import WebElement
|
||||||
|
|
||||||
@ -213,3 +214,25 @@ class DriverPage(object):
|
|||||||
def chrome_downloading(self, download_path: str) -> list:
|
def chrome_downloading(self, download_path: str) -> list:
|
||||||
"""检查下载情况"""
|
"""检查下载情况"""
|
||||||
return glob(f'{download_path}\\*.crdownload')
|
return glob(f'{download_path}\\*.crdownload')
|
||||||
|
|
||||||
|
def process_alert(self, mode: str = 'ok', text: str = None) -> Union[str, None]:
|
||||||
|
"""处理提示框
|
||||||
|
:param mode: 'ok' 或 'cancel',若输入其它值,不会按按钮但依然返回文本值
|
||||||
|
:param text: 处理prompt提示框时可输入文本
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
alertObject = self.driver.switch_to.alert
|
||||||
|
except NoAlertPresentException:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if text:
|
||||||
|
alertObject.send_keys(text)
|
||||||
|
|
||||||
|
text = alertObject.text
|
||||||
|
if mode == 'cancel':
|
||||||
|
alertObject.dismiss()
|
||||||
|
elif mode == 'ok':
|
||||||
|
alertObject.accept()
|
||||||
|
|
||||||
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user