2012-01-18 133 views

回答

1

我不會嘗試混合SeleniumRC(版本1 API)與WebDriver(版本2 API)。這將是兩次痛苦,沒有樂趣。

使用webdriver的,你有沒有試過

import contextlib 
import selenium.webdriver as webdriver 
with contextlib.closing(webdriver.Firefox()) as driver: 
    driver.implicitly_wait(10) 
    driver.get('http://www.google.com') 
    # driver.get_screenshot_as_file('/tmp/google.png') 
    driver.save_screenshot('/tmp/google.png') 
0

你可以相信你所看到的錯誤詳細點嗎?也許有一些你的代碼錯誤。這工作完全適合我在Selenium 1中:

from selenium import selenium 
import unittest, time, re 

class IIIAppforloop(unittest.TestCase): 
    def setUp(self): 
     self.verificationErrors = [] 
     self.selenium = selenium("localhost", 4444, "*firefox", "http://www.yahoo.com/") 
     self.selenium.start() 

    def test_i_i_i_appforloop(self): 
     sel = self.selenium 
     sel.open("/") 
     sel.wait_for_page_to_load(60000) 
     sel.capture_entire_page_screenshot(r"C:\picture.png", " ") 


    def tearDown(self): 
     self.selenium.stop() 
     self.assertEqual([], self.verificationErrors) 

if __name__ == "__main__": 
    unittest.main()