from selenium import webdriver
browserFirefox = webdriver.Firefox()
print(type(browserFirefox))
browserFirefox.get('http://www.baidu.com')
elem_baidu = browserFirefox.find_element_by_class_name('s_form')#查找名字为s_form的标签,返回WebElement对象elem_baidu
print(elem_baidu.tag_name)#打印名字为s_form的标签,WebElement对象elem_baidu调用tag_name
linkElem = browserFirefox.find_element_by_link_text('hao123')#查找名字为s_form的文字链接,返回WebElement对象linkElem
linkElem.click()#WebElement对象linkElem调用click()方法打开该链接页面
#提交表单
#登录QQ邮箱
browserFirefoxEmail = webdriver.Firefox()
browserFirefoxEmail.get('https://mail.qq.com/')#
#switchLoginElem = browserFirefoxEmail.find_element_by_id('switcher_qlogin')
#switchLoginElem.double_click()
browserFirefoxEmail.switch_to_frame('login_frame')
browserFirefoxEmail.find_element_by_id('u').clear()
browserFirefoxEmail.find_element_by_id('u').send_keys('670148752@qq.com')
browserFirefoxEmail.find_element_by_id('p').clear()
browserFirefoxEmail.find_element_by_id('p').send_keys('pz198976')
browserFirefoxEmail.find_element_by_id('login_button').click()
#登录QQ空间
driver = webdriver.Firefox()
#设置浏览器窗口的位置和大小
driver.set_window_position(20, 40)
driver.set_window_size(1100,700)
#打开一个页面(QQ空间登录页)
driver.get('http://qzone.qq.com')
#登录表单在页面的框架中,所以要切换到该框架
driver.switch_to_frame('login_frame')
#通过使用选择器选择到表单元素进行模拟输入和点击按钮提交
driver.find_element_by_id('switcher_plogin').click()
driver.find_element_by_id('u').clear()
driver.find_element_by_id('u').send_keys('670148752')
driver.find_element_by_id('p').clear()
driver.find_element_by_id('p').send_keys('pz18860375172')
driver.find_element_by_id('login_button').click()
#自动登录bug管理系统
browserBug = webdriver.Firefox()
browserBug.get('http://192.168.0.8:82/zentao/user-login.html')#
browserBug.find_element_by_id('account').send_keys('habo')
browserBug.find_element_by_name('password').send_keys('123456')
browserBug.find_element_by_id('submit').click()
python实现自动登录
本文转载:CSDN博客