測試代碼:
<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能通過!!