【发布时间】:2016-05-05 08:20:20
【问题描述】:
1.这是test_loginqq.py的代码:
#coding=utf-8
from selenium import webdriver
import time
class loginout():
def test_login(self,driver):
driver = webdriver.Firefox()
driver.get("https://en.mail.qq.com/cgi-bin/loginpage")
driver.implicitly_wait(30)
driver.switch_to_frame("login_frame")
driver.find_element_by_id("switcher_plogin").click()
driver.find_element_by_id("u").clear()
driver.find_element_by_id("u").send_keys("*****")
#driver.find_element_by_id("emailTips_0").click()
driver.find_element_by_id("p").clear()
driver.find_element_by_id("p").send_keys("****")
driver.find_element_by_id("login_button").click()
title=driver.title
print (title)
driver.implicitly_wait(30)
user=driver.find_element_by_id("useraddr").text
print user
print "log in successfully"
#driver.quit()
def test_logout(self,driver):
#driver.implicitly_wait(30)
driver.find_element_by_xpath("//a[test()='Sign out']").click()
title=driver.title
print title
driver.quit()
2.这是test_main.py的代码:
#coding=utf-8
from selenium import webdriver
from test_loginqq import loginout
import time
import unittest
class my_test(unittest.TestCase):
def setUp(self):
print "test start"
def test_test(self):
loginout().test_login(self)
loginout().test_logout(self)
def test_test0(self):
a="hello"
b="hello world"
self.assertIn(a,b,msg='a is not in b')
def tearDown(self):
print "test end"
if __name__=='__main__':
suite=unittest.TestLoader().loadTestsFromTestCase(my_test)
unittest.TextTestRunner(verbosity=2).run(suite)
3.当我运行 test_main.py 时,我得到一个错误:'my_test' object has no attribute 'find_element_by_xpath',我对此一无所知,有人可以帮我解决我的问题吗?
【问题讨论】:
-
我使用 selenium IDE 记录我的脚本,当我试图定位元素“退出”时,我得到一个错误:Caught exception [ERROR: Unsupported command [selectWindow |空 | ]]。 ...希望这能有所帮助
标签: python error-handling find element