Python Login Script

Source: Internet
Author: User

The core of the key is to compare the changes in the page before and after

  1. Code version 1
  2. # coding=utf-8#
    #导入webdriver模块
    From selenium import Webdriver
    From time import sleep
    # Webdriver Local directory, specified to exe
    Execute_path = R ' C:\Program Files (x86) \google\chrome\application\chromedriver.exe '
    Equal_string= ' 2016? Nanjing Old man Jia Intelligent Technology Co., Ltd.
    # Specify a driver for Chrome
    # when we get here, selenium will go to the specified path and run the Chrome driver program.
    Driver=webdriver. Chrome (Execute_path)
    # Use the Get method to open the specified Web site
    Driver.get (' http://itest.chinacloudapp.cn:8280/')
    # Get the elements above the page find_element_by_id_xxx
    #· Text gets the literal of the element

    # Analog Login operation
    # get positioning, enter values

    Login_url=driver.current_url
    driver.find_element_by_id (' UserName '). Send_keys (' ly ')
    driver.find_element_by_id (' password '). Send_keys (' [Email protected]# ')
    #查询包含doLogin的字符
    Driver.find_element_by_css_selector (' button[onclick*= ' Dologin "] '). Click ()

    # implicit waiting
    Sleep (2)
    # driver.implicitly_wait (10)

    # Cookies=driver.get_cookie ()
    #
    # Print Cookies

    Homepage_url=driver.current_url

    If Homepage_url==login_url:
    print ' Login failed '
    Else
    print ' Landing success '

    # Check version information

    Try
    Ele=driver.find_element_by_class_name ("Copyright"). Text
    Print Ele
    # When using text comparison, you need to consider the encoding
    if ele = = Equal_string.decode (' Utf-8 '):
    print ' Version information correct '
    Else
    print ' Version information error '
    Except
    print ' Version information error '
    Driver.close ()




Python Login Script

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.