在测试中,有时候会遇到弹窗的问题,有的是浏览器弹窗(alert)、有的是⾃定义弹窗;这节我们主要来讨论⼀下关于浏览器弹窗和简单的⾃定包的源码展⽰
:Args:
- driver: The WebDriver instance which performs user actions.
"""
self.driver = driver
@property
def text(self):
"""
Gets the text of the Alert.
"""
return ute(Command.GET_ALERT_TEXT)["value"]
def dismiss(self):
"""
Dismisses the alert available.
"""
ute(Command.DISMISS_ALERT)
def accept(self):
"""
Accepts the alert available.
Usage::
Alert(driver).accept() # Confirm a alert dialog.
"""
ute(Command.ACCEPT_ALERT)
def send_keys(self, keysToSend):
"""
Send Keys to the Alert.
:Args:
- keysToSend: The text to be sent to Alert.
"""
if self.driver.w3c:
ute(Command.SET_ALERT_VALUE, {'value': keys_to_typing(keysToSend)}) else:
ute(Command.SET_ALERT_VALUE, {'text': keysToSend})
def authenticate(self, username, password):
web浏览器在哪里打开
"""
Send the username / password to an Authenticated dialog (like with Basic HTTP Auth). Implicitly 'clicks ok'
Usage::
driver.switch_to.alert.authenticate('cheese', 'secretGouda')
:Args:
-username: string to be set in the username section of the dialog
-password: string to be set in the password section of the dialog
"""
ute(
Command.SET_ALERT_CREDENTIALS,
{'username': username, 'password': password})
self.accept()
三、实例:w3c的alert页⾯
代码展⽰:
from selenium import webdriver
from selenium import webdriver

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。