日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

pythonalert弹窗_python+selenium八:Alert弹窗

發布時間:2024/1/23 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pythonalert弹窗_python+selenium八:Alert弹窗 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

# 此彈窗是瀏覽器自帶的彈窗,不是html中的元素

from selenium import webdriver

from selenium.webdriver.common.action_chains import ActionChains

import time

from selenium.webdriver.support.select import Select

driver = webdriver.Firefox()

url = "https://www.baidu.com"

driver.get(url)

time.sleep(3)

mouse = driver.find_element("link text", "設置")

ActionChains(driver).move_to_element(mouse).perform()

time.sleep(0.5)

driver.find_element("link text", "搜索設置").click()

time.sleep(1)

# 先定位到下拉框

s = driver.find_element_by_id("nr")

Select(s).select_by_visible_text("每頁顯示20條")

s.click()

time.sleep(1)

# 點擊保存按鈕,此時會彈出確認提示框

driver.find_element_by_class_name("prefpanelgo").click()

time.sleep(0.5)

# 獲取彈窗

a = driver.switch_to_alert()

# 或者

# a = driver.switch_to.alert

print(a.text) # 打印彈窗的文字內容

# 1、accept() 彈框的確定按鈕

a.accept() # 點確定按鈕

# 2、dismiss() 彈框的取消按鈕

a.dismiss() # 點取消按鈕

# 3、彈框若有輸入框,需輸入內容

a.send_keys("xxxx")

總結

以上是生活随笔為你收集整理的pythonalert弹窗_python+selenium八:Alert弹窗的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。