0
点赞
收藏
分享

微信扫一扫

selenium-弹出框、下拉框

您好 2024-01-13 阅读 16

弹出框

        对js使用的alert、confirm 以及 prompt定位也是项目中常见的,比如弹出提 示框“确定”等。要定位这类提示框具体思路是switch_to_alert()方法定位 alert/confirm/prompt,然后使用text/accept/dismiss/send_keys这一系列动作。

  • driver.switch_to.alert.accept()         #点击ok
  • driver.switch_to.alert.text                 #得到对话框内容
  • driver.switch_to.alert.dismiss()         #点击Cancel
  • driver.switch_to.alert.send_keys()         #输入内容

下拉框

常见下拉框操作包含在selenium.webdriver.support.select的Select 类中,常用的方法:

  • select_by_value(' value') 通过value值选择
  • select_by_visible_text('text') 通过文本选择
  • select_by_index(index) 通过索引选择,索引从0开始

举报

相关推荐

0 条评论