>

selenium自动化登陆qq网页,自动登入1二陆信箱

- 编辑:www.bifa688.com -

selenium自动化登陆qq网页,自动登入1二陆信箱

在举办登入12陆邮箱时有多少个坑,要完善避过可以看一下下文,直接上代码:

多少个简单的登入网页上qq的本子,通过此脚本驾驭到稍微岗位是无能为力通过xpath来牢固的相反是By定位更便利

# -*- coding: utf-8 -*-

#encoding = utf-8

#encoding=utf-8

from selenium import webdriver

from selenium import webdriver
import unittest
import time
class login126(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path = "chromedriver")

from selenium import webdriver

fromselenium.webdriver.common.byimportBy

def test_login(self):
self.driver.get("")
time.sleep(3)
#那边的登入框是在iframe里,所以自然要先进入iframe,然后才干找到成分
self.driver.switch_to.frame(self.driver.find_element_by_xpath(".//*[@id='x-URS-iframe']"))
time.sleep(3)
#签到和密码输入框要记住不要用ID来进展一定,每一次登入ID都会开始展览转移的
self.driver.find_element_by_xpath(".//*[@data-placeholder='邮箱帐号或手提式有线电话机号']").send_keys('xxxx')
self.driver.find_element_by_xpath('//*[@data-placeholder="密码"]').send_keys('xxxxx')
self.driver.find_element_by_xpath('//*[@id="dologin"]').click()
## self.driver.switch_to.default_content()
#预知前要等待页面加载出来后在开始展览预感
time.sleep(10)
assert u'退出' in self.driver.page_source

import unittest,time

fromselenium.webdriver.common.keysimportKeys

def tearDown(self):
self.driver.quit()

class QQmail(unittest.TestCase):

fromselenium.webdriver.support.uiimportSelect

if __name__ == '__main__':
unittest.main()

  def setUp(self):

fromselenium.common.exceptionsimportNoSuchElementException

    self.driver=webdriver.Firefox()

fromselenium.common.exceptionsimportNoAlertPresentException

    self.driver.get("")

importunittest, time, re

    def test_login(self):

classTestOne(unittest.TestCase):

    driver=self.driver

defsetUp(self):

    driver.switch_to.frame("login_frame")#弹出三个frame来输入消息

self.driver = webdriver.Firefox()

    driver.find_element_by_id("u").click()

self.driver.implicitly_wait(30)

    driver.find_element_by_id("u").clear()#清楚暗中认可值

self.base_url =""

    driver.find_element_by_id("u").send_keys('qq号')

self.verificationErrors = []

    #driver.find_element_by_xpath("//*[@id="p"]").click()#用xpath不可能识别p那些id

self.accept_next_alert =True

    driver.find_element_by_id("p").click()

deftest_one(self):

    driver.find_element_by_id("p").clear()

driver =self.driver

    driver.find_element_by_id("p").send_keys('qq密码')

driver.get(self.base_url "/ums/coframe/auth/login/login.jsp")

    driver.find_element_by_id("login_button").click()

driver.find_element_by_id("userId$text").clear()

 

driver.find_element_by_id("userId$text").send_keys("sysadmin")

def tearDown(self):

driver.find_element_by_id("password$text").clear()

  self.driver.quit()

driver.find_element_by_id("password$text").send_keys("000000")

 

driver.find_element_by_css_selector("input.log").click()

if __name__=='__main__':

driver.find_element_by_xpath("(//a[@onclick='return false;'])[4]").click()

  unittest.main()

driver.find_element_by_xpath("(//a[@onclick='return false;'])[5]").click()

driver.find_element_by_xpath("//td[@id='53$cell$1']/div/div/span[4]").click()

# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | main | ]]

driver.find_element_by_xpath("//a[3]/span").click()

driver.find_element_by_css_selector("#mini-32 > span.mini-button-text.").click()

defis_element_present(self, how, what):

try:self.driver.find_element(by=how,value=what)

exceptNoSuchElementExceptionase:returnFalse

returnTrue

defis_alert_present(self):

try:self.driver.switch_to_alert()

exceptNoAlertPresentExceptionase:returnFalse

returnTrue

defclose_alert_and_get_its_text(self):

try:

alert =self.driver.switch_to_alert()

alert_text = alert.text

ifself.accept_next_alert:

alert.accept()

else:

alert.dismiss()

returnalert_text

finally:self.accept_next_alert =True

deftearDown(self):

self.driver.quit()

self.assertEqual([],self.verificationErrors)

if__name__ =="__main__":

unittest.main()

自动化测试群:3693535八三

本文由必发88手机版发布,转载请注明来源:selenium自动化登陆qq网页,自动登入1二陆信箱