51Testing软件测试论坛

标题: python2.7+selenium3---求教各位大神 [打印本页]

作者: 测试小白文    时间: 2017-7-18 17:37
标题: python2.7+selenium3---求教各位大神
使用xml文件做“数字驱动测试”
代码如下:
  1. info.xml[code]<?xml version="1.0" encoding="utf-8"?>
  2. <catalog>
  3. <explain>中国移动139邮箱</explain>
  4. <url>http://mail.10086.cn/</url>
  5. <all_null username="" password="">请输入帐号</all_null>
  6. <pawd_null username="testingwtb" password="">请输入邮箱密码</pawd_null>
  7. <user_null username="" password="a123456">请输入帐号</user_null>
  8. <yes username="15919825333" password="******">15919825333</yes>
  9. <error username="xxx" password="xxx">帐号或密码错误</error>
  10. </catalog>
复制代码


py文件如下:
  1. #coding:UTF-8
  2. from selenium import webdriver
  3. import unittest
  4. from xml.dom import minidom

  5. dom = minidom.parse('C:\\Users\\Administrator\\Desktop\\info.xml')
  6. root = dom.documentElement
  7. class Test_139(unittest.TestCase):
  8.     def setUp(self):
  9.         self.driver = webdriver.Ie()
  10.         self.driver.implicitly_wait(30)
  11.         logns = root.getElemntByTagName('url')
  12.         self.url =logns[0].firstChild.data
  13.         self.verificationErrors= []
  14.     def test_all_null(self):
  15.         driver = self.driver
  16.         driver.get(self.url)
  17.         longs = root.getElemntByTagName('all_null')
  18.         username = longs[0].getAttribute('username')
  19.         password = longs[0].getAttribute('password')
  20.         Text = longs[0].firstChild.data
  21.         driver.find_element_by_name('UserName').send_keys(username)
  22.         driver.find_element_by_class_name('Password').send_keys(password)
  23.         driver.find_element_by_id('loginBtn').click()
  24.         test = driver.find_element_by_id('tip_user_msg').text
  25.         self.assertEqual(test, Text)
  26.         
  27.    
  28. if __name__ == '__main__':
  29.     unittest.main()  
复制代码


运行后报错了,如下:
  1. Traceback (most recent call last):
  2.   File "D:\Escplise\workspace\Pytest\src\test001\test\test003.py", line 7, in <module>
  3.     dom = minidom.parse('C:\\Users\\Administrator\\Desktop\\info.xml')
  4.   File "C:\Python27\lib\xml\dom\minidom.py", line 1918, in parse
  5.     return expatbuilder.parse(file)
  6.   File "C:\Python27\lib\xml\dom\expatbuilder.py", line 924, in parse
  7.     result = builder.parseFile(fp)
  8.   File "C:\Python27\lib\xml\dom\expatbuilder.py", line 207, in parseFile
  9.     parser.Parse(buffer, 0)
  10. xml.parsers.expat.ExpatError: not well-formed (invalid token): line 3, column 9
复制代码


,小白一个,不知道错误原因,求大神帮助!!!
作者: finomy    时间: 2017-7-19 09:30
“info.xml[code]” xml文件最前面的这个是做什么用的?感觉是xml文件格式的问题。你把info.xml[code]删掉试试看。还有看一下xml文件的编码,编码有可能不是utf8




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2