Selenium+python+eclipse implementation of "questionnaire Star" website, login and check login sample!

Source: Internet
Author: User



1, using Selenium+python+eclipse to achieve the login "questionnaire Star", the questionnaire Star access address: https://www.sojump.com/



2, the implementation of the steps: 1) into the link---home---click "Login"---Enter the account, password----login



2) Check if login is successful



3. Page:






4, the code contains the points:



1) log information to print and save in a particular file 2) point of Judgment Add 3) basic operation, see the following code in detail


 
# coding=UTF-8
''
Created on May 4, 2017
@author: SYW
''
import unittest
from selenium import webdriver
Import time
from logs import logging
class Test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.base_url = "https://www.sojump.com/"
def tearDown(self):
unittest.TestCase.tearDown(self)
def User_Login(self,userNumber,PassWord):
Method introduction: enter the questionnaire star to log in
Parameter introduction: Username: user name, password: user password
''
driver = self.driver
driver.get(self.base_url)
Logging.info ("has entered the questionnaire star page! ""
time.sleep(1)
Driver. Maximize? Window()? Maximize window display
Driver. Find  element  by  XPath ("/ / Li [@ id = 'ctl00  lilogin'] / A / span"). Click()  click the page "login"
time.sleep(1)
User = driver.find? Element? By? ID ("ctl00? Contentplaceholder1? Username")? User account input box
If user:
User.click ()
user.send_keys(userNumber)
Else:
Logging.error ("user input box positioning failed! ""
Driver. Find? Element? By? ID ("ctl00? Contentplaceholder1? Password"). Send? Keys (password)? User password input box, and enter the password
Logging.info ("click login button")
Driver. Find? Element? By? ID ('ctl00? Contentplaceholder1? LoginButton '). Click()? Login button
def Check_User_Login(self):
Logging.info ("check login! ""
driver = self.driver
Time.sleep (2) ා stay for 2 seconds, and give the page load buffer time
For I in range (2): loop twice to avoid network problems
Try:
If "00000000001t" = = driver. Find ﹐ element ﹐ by ﹐ ID ("ctl01 ﹐ lblusername"). Text: ﹐ get the user nickname after the login account and the known account nickname for comparison and judgment
Logging.info ("questionnaire star login succeeded! ""
Break
Else:
Logging. Error ("questionnaire star login failed! ""
Exception: logging.error ("exception, questionnaire star login failed! ""
Time.sleep (1) × the waiting time at the end of each cycle, which can be defined by yourself
def test_Name(self):
self.User_Login(‘18392868125‘,‘855028741616‘)
self.Check_User_Login()
if __name__ == "__main__":
unittest.main()


Run Results log print form: [2017-05-05 16:10:59,174] [line:48] [INFO]: Questionnaire Star Login Success! Ran 1 Test in 12.057s OK






Selenium+python+eclipse implementation of "questionnaire Star" website, login and check login sample!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.