python 获取alert信息并截取alert图片

 





获取option的值和文本











您输入的用户名或密码有误。




javascript





-----------------------------------------------------------------------------------------------------------------------

# coding:utf-8
from selenium import webdriver
from PIL import ImageGrab
import time

browser = webdriver.Firefox()
url = 'file:///C:/Users/liqq/Desktop/option.html'
browser.get(url)

select = browser.find_element_by_link_text("javascript")
select.click()
a = browser.switch_to_alert()
print a.text
if a.text.encode('utf-8') == "麦当劳":
    print "--------------------"
    time.sleep(2)
filename = "D:\\work\\YZ\\trunk\\result\\screenshot\\" + 'test_alert.jpg'
try:
    browser.find_element_by_id('NoSuch_element')
except:
    browser.get_screenshot_as_file(filename)

select.click()
try:
    browser.find_element_by_id('NoSuch_element')
except:
    im = ImageGrab.grab()
    im.save("D:\\1.jpg")
browser.quit()


你可能感兴趣的:(python 获取alert信息并截取alert图片)