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