2016-06-13 6 views
0

私はPython 3とPhantomJSを使用しています。私は警告のテキストを取得したいが、私は私のプロジェクトをコンパイルするとき、私はエラーPhantomJS Pythonの警告

Traceback (most recent call last): 
    File "C:/Users/Dante/Documents/GitHub/ProjectHeisenberg/BioInfoRNA/Main.py", line 8, in <module> 
    class Main: 
    File "C:/Users/Dante/Documents/GitHub/ProjectHeisenberg/BioInfoRNA/Main.py", line 63, in Main 
    print(alert.text) 
    File "C:\Python3\lib\site-packages\selenium\webdriver\common\alert.py", line 65, in text 
    return self.driver.execute(Command.GET_ALERT_TEXT)["value"] 
    File "C:\Python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute 
    self.error_handler.check_response(response) 
    File "C:\Python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response 
    raise exception_class(value) 
selenium.common.exceptions.WebDriverException: Message: Invalid Command Method - {"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:50844","User-Agent":"Python-urllib/3.5"},"httpVersion":"1.1","method":"GET","url":"/alert_text","urlParsed":{"anchor":"","query":"","file":"alert_text","directory":"/","path":"/alert_text","relative":"/alert_text","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/alert_text","queryKey":{},"chunks":["alert_text"]},"urlOriginal":"/session/24c37130-3103-11e6-bf6e-074d3d3fe80d/alert_text"} 

を持っており、これは私のコードの断片である:

alert = browser.switch_to_alert() 
browser.switch_to_alert() 
print(alert.text) 

私はこの問題を解決するにはどうすればよいですか?

+0

を使用しますか? – alecxe

+0

@alecxeバージョン:2.1.1 – DanteVoronoi

+0

'selenium'パッケージを最新バージョンにアップグレードするとどうでしょうか? 'pip3 install --upgrade selenium' – alecxe

答えて

-1

あなたは何 `PhantomJS`のバージョンを使用しているこの

driver.execute_script("window.confirm = function(msg) { return true; }"); 
+3

この回答が現在の問題を解決するためにOPをどのように助けてくれるかについての説明を追加してください –

+0

このコードスニペットは問題を解決するかもしれませんが[http: /meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)は本当にあなたの投稿の質を向上させるのに役立ちます。将来読者の質問に答えていることを覚えておいてください。そうした人々はあなたのコード提案の理由を知らないかもしれません。 – DimaSan

+0

は私の問題を解決しません – gh4x