美文网首页
select和alert

select和alert

作者: 酷飒de小姐姐 | 来源:发表于2021-05-25 19:42 被阅读0次

    一、select下拉框

    1、下拉框

    2、多选项

    二、alert弹窗

    1、accept()

    2、dismiss()

    3、text

    #!/usr/bin/python3

    # coding:utf-8

    from seleniumimport webdriver

    from selenium.webdriver.common.action_chainsimport ActionChains

    from selenium.webdriver.support.selectimport Select

    import time

    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(3)

    # driver.find_element_by_class_name("link text", "搜索设置").click()

    driver.find_element_by_class_name("setpref").click()

    time.sleep(3)

    # driver.find_element_by_xpath(".//*[@id='nr']/option[3]").click()

    # parent = driver.find_element_by_id("nr")

    #  parent.find_element_by_xpath('.//option[@value="20"]').click()

    abc = driver.find_element_by_id("nr")

    # Select(abc).select_by_index(0)

    #  index�Select(abc).select_by_value("50")

    Select(abc).select_by_visible_text("每页显示20条")

    time.sleep(1)

    #alert

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

    # 等待两秒,等弹出框弹出来

    time.sleep(2)

    a = driver.switch_to.alert

    print(a.text)

    a.accept()

    # 打印弹出框文本信息

    # print(a.text)

    # 确定按钮

    # a.accept()

    #alert处理方法

    driver.close()

    #!use/bin/python3

    # coding:utf-8

    from seleniumimport webdriver

    import time

    # driver = webdriver.Firefox()

    driver = webdriver.Chrome()

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

    driver.get("https://www.baidu.com")

    # # 点击保存设置按钮

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

    # # 等待两秒,等弹出框弹出来

    # time.sleep(2)

    # a = driver.switch_to.alert

    # # 打印弹出框文本信息

    # print(a.text)

    # # 确定按钮

    # a.accept()

    # #不想打印文本信息

    # driver.switch_to.alert.accept()#弹出alert框并点击确定按钮

    # switch_to.alert()获取弹出框文本:text

    # accept()确定

    # dismiss()取消

    # send_keys()输入值

    # 打印获取全部窗口

    # 打印所有的handle

    # all_handes = driver.window_handles

    # print(all_handes)

    # # 切换到新的handle上

    # driver.switch_to.window(all_handes[1])

    driver.maximize_window()

    time.sleep(2)

    link = driver.find_element_by_id("s-usersetting-top").click()

    # driver.find_element_by_class_name("setpref").click()

    driver.find_element_by_link_text("搜索设置").click()

    time.sleep(3)

    #保存设置

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

    #获取警告弹框文本

    alert = driver.switch_to.alert

    print(alert.text)

    #接受弹框

    alert.accept()

    driver.quit()

    相关文章

      网友评论

          本文标题:select和alert

          本文链接:https://www.haomeiwen.com/subject/rfrojltx.html