2017-10-01 11 views
-1

私はPython 2.7.13、Seleniumバージョン3.3.3、PhantomJS 2.1.1をhttps://phantomjs.orgからダウンロードしています。TimeoutException phantomjsでEC.text_to_be_present_in_elementを使用

Fedora 25(またはWindows 7)で次のスクリプトを実行すると、Firefoxで正常に動作しますが、PhantomJSでselenium.common.exceptions.TimeoutExceptionが発生します。 PhantomJSで

$ python test.py 
Check http://phantomjs.org/ title 
. 
---------------------------------------------------------------------- 
Ran 1 test in 9.433s 

OK 

::Firefoxで

from selenium import webdriver 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.by import By 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 
from selenium.common.exceptions import NoSuchElementException 
import unittest2 

FF = True 
#FF = False 

class Test(unittest2.TestCase): 

    @classmethod 
    def setUpClass(self): 
     if FF: 
      binary = FirefoxBinary('/usr/bin/firefox') 
      d = DesiredCapabilities.FIREFOX 
      self.driver = webdriver.Firefox(firefox_binary=binary) 
     else: 
      self.driver = webdriver.PhantomJS("phantomjs") 
      self.driver.maximize_window() 

     self.base_url = "http://phantomjs.org/" 
     self.verificationErrors = [] 
     self.accept_next_alert = True 
     self.result = 0 

    def test01(self): 
     driver = self.driver 
     driver.get(self.base_url) 

     print("Check http://phantomjs.org/ title") 
     WebDriverWait(driver, 10).until(
      EC.text_to_be_present_in_element((By.XPATH, "/html/head/title"), "PhantomJS | PhantomJS") 
     ) 

    @classmethod 
    def tearDownClass(self): 
     self.driver.quit() 

if __name__ == "__main__": 
    unittest2.main(failfast=True) 

$ python test.py 
Check http://phantomjs.org/ title 
E 
====================================================================== 
ERROR: test01 (__main__.Test) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "test.py", line 36, in test01 
    EC.text_to_be_present_in_element((By.XPATH, "/html/head/title"), "PhantomJS | PhantomJS") 
    File "/usr/lib/python2.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until 
    raise TimeoutException(message, screen, stacktrace) 
selenium.common.exceptions.TimeoutException: Message: 


---------------------------------------------------------------------- 
Ran 1 test in 21.169s 

FAILED (errors=1) 
+0

あなたの質問は何であるに記載されているライブラリコールの一つでしたか? – Andersson

答えて

0

私は

EC.text_to_be_present_in_element((By.XPATH, "/html/head/title"), "PhantomJS | PhantomJS") 

を変更することにより、それを修正

EC.title_contains("PhantomJS | PhantomJS") 

これはdocs

関連する問題