作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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()
#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)
最佳答案
您应该在登出类中实例化webdriver.Firefox()
这段代码也许你想要:
#coding=utf-8
from selenium import webdriver
import time
class loginout():
def test_login(self, driver):
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()
#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):
driver = webdriver.Firefox()
loginout().test_login(driver)
loginout().test_logout(driver)
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)
关于python - “my_test”对象没有属性 'find_element_by_xpath',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045762/
1.这是test_loginqq.py的代码: #coding=utf-8 from selenium import webdriver import time class loginout(
我是一名优秀的程序员,十分优秀!