基于python3的自动化测试框架selenium3实践
登录网易邮箱(126,163)
登录163
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #!/usr/bin/env python3 # -*- coding: utf-8 -*-
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time
browser = webdriver.Chrome() browser.get('http://mail.163.com/') browser.maximize_window()
#切换进iframe browser.implicitly_wait(5) browser.switch_to.frame('x-URS-iframe') time.sleep(1)
#定位账号 username = browser.find_element_by_name('email') username.clear() username.send_keys('***') time.sleep(1) #定位密码 pwd = browser.find_element_by_name('password') pwd.clear() pwd.send_keys('***')
#登录 pwd.send_keys(Keys.ENTER) time.sleep(3) browser.quit()
|
或者
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #coding:utf-8 from selenium import webdriver from selenium.webdriver.common.keys import Keys import time
driver = webdriver.Firefox() driver.get('http://mail.163.com/') driver.implicitly_wait(10) #切换iframe iframe = driver.find_elements_by_tag_name('iframe') driver.switch_to_frame(iframe) #driver.switch_to.frame('x-URS-iframe') driver.find_element_by_name('email').send_keys('123') driver.find_element_by_name('password').send_keys('456') brower.find_element_by_name("password").send_keys(Keys.ENTER)
|
登录126
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #!/usr/bin/env python3 # -*- coding: utf-8 -*-
import time from selenium import webdriver from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome() browser.get('http://mail.126.com/') browser.maximize_window()
# 切换iframe browser.implicitly_wait(5) browser.switch_to.frame('x-URS-iframe') time.sleep(1)
# 定位用户名 username = browser.find_element_by_name('email') username.clear() username.send_keys('***') time.sleep(1)
#定位密码 pwd = browser.find_element_by_name('password') pwd.clear() pwd.send_keys('***')
#登录 pwd.send_keys(Keys.ENTER) time.sleep(3) browser.quit()
|
~记小白入坑selenium