测试代码:
<span style="font-size:18px;"><span style="background-color: rgb(255, 255, 255);">#-*-coding:utf-8-*-
from selenium import webdriver
import unittest
class Login(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://blog.csdn.net"
self.verificationErrors = []
self.accept_next_alert = True
def test_login(self):
driver = self.driver
driver.get(self.base_url + "/spring292713")
driver.find_element_by_link_text(u"登录").click()
driver.switch_to_frame("logfrm")
driver.find_element_by_id("u").clear()
driver.find_element_by_id("u").send_keys("spring292713")
driver.find_element_by_id("p").clear()
driver.find_element_by_id("p").send_keys("xxxoo")
driver.find_element_by_id("aLogin").click()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()</span><span style="color:#3333ff;"><strong>
</strong></span></span>
若登陆成功,说明OK了!!
<span style="background-color: rgb(0, 153, 0); color: rgb(255, 255, 255); font-size: 18px; font-family: Arial, Helvetica, sans-serif;">加上 chromedriver.exe 和 IEDriverServer.exe 后,降代码的第六行改成</span>
driver = webdriver.Ie() 或 driver = webdriver.Chrome() 可测试在IE或Chrome下的效果。
但是很不幸,我在win7下测试成功,在XP下测试只有Firefox能通过!!