美文网首页
python + selenium 处理下拉框/alert

python + selenium 处理下拉框/alert

作者: 柔指清风 | 来源:发表于2019-08-05 22:28 被阅读0次

    from seleniumimport webdriver

    from selenium.webdriver.support.selectimport Select

    from selenium.webdriver.common.action_chainsimport ActionChains

    import time

    # 下拉框定位

    driver = webdriver.Chrome()

    driver.maximize_window()

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

    driver.get(url)

    driver.implicitly_wait(10)

    a = driver.find_element_by_link_text("设置")

    ActionChains(driver).move_to_element(a).perform()

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

    time.sleep(3)

    # driver.find_element_by_id("nr").click()

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

    b = driver.find_element_by_id("nr")

    Select(b).select_by_index(2)

    b.click()

    Select(b).select_by_value("50")

    b.click()

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

    b.click()

    driver.find_element_by_link_text("保存设置").click()

    #针对Alert弹窗处理

    c = driver.switch_to.alert#切换到alert

    d = c.text

    print(d)

    time.sleep(3)

    c.accept()

    driver.quit()

    相关文章

      网友评论

          本文标题:python + selenium 处理下拉框/alert

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