Selenium+python automation, Data-driven Instances

Source: Internet
Author: User
Tags tag name tagname

1. Read txt

Read () reads the entire file.

ReadLine () reads a row of Data.

ReadLines () reads all rows of Data.

Example: #coding =utf-8from Selenium Import Webdriver

User_file = open (' user_info.txt ', ' r ')

Values = User_file.readlines ()

User_file.close ()

For Serch in Values:

Username = serch.split (', ') [0]

Print username

    Password = serch.split (', ') [1]    Print Password

2. Read CSV

#coding =utf-8
Import CSV

# Read local CSV file
My_file= ' info.csv ' date=csv.reader (file (my_file, ' RB '))

# loop out each line of information

For user in Date:

Print user

3. Reading XML

XML Extensible Markup language, which can be used to tag data, define data types, is a source language that allows users to define their own markup language.

XML has the following characteristics: first, it is tagged to the constituent:<aa></aa> tag can have attributes: <aa id= ' 123 ' ></aa> tag pair can embed Data: <AA>ABC</AA >

Example: #coding =utf-8
Import Xml.dom.minidom

# Open XML document
Dom = Xml.dom.minidom.parse (' info.xml ')

# Get Document Element object
root = Dom.documentelementprint Root.nodename
Print Root.nodevalue
Print Root.nodetype
Print Root. Element_node

Mxl.dom.minidom
The Mxl.dom.minidom module is used to process XML files, so it should be introduced First.

Parse ()
Xml.dom.minidom.parse () is used to open an XML file and will be the DOM variable for this file Object.

DocumentElement
DocumentElement is used to get the document elements of the DOM object and to give the obtained object to root

Each node has its nodename,nodevalue,nodetype Property. NodeName is the node Name.
NodeValue is the value of the node and is valid only for text Nodes.
NodeType is the type of Node.

Getelementbytagname () can get a tag from a tag name. The object it obtains is stored in an array form. If the "caption" and "item" labels have more than one in the Info.xml file, you can specify the subscript of the array to get a label.

Root.getelementsbytagname (' caption ') is a set of labels labeled caption; Tagname[0] represents the first of a set of Labels.
Tagname[2] represents the third of a group of Labels.

The GetAttribute () getattribute () method can get the value corresponding to the attribute of the Element.

Selenium+python automation, Data-driven instances

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.