2016-03-03 79 views
1

我想追查Python Selenium中的錯誤。該錯誤消息是..Python硒解密錯誤消息

Traceback (most recent call last): 
    File "C:\myscipt\main.py", line 110, in <module> 
    source_mysource(func1, func2, func3, func4, func5, func6, func7, func8, func9) 
    File "C:\myscipt\sources\functions.py", line 132, in source_mysource 
    current_url = driver.current_url 
    File "C:\Users\tom\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 454, in current_url 
    return self.execute(Command.GET_CURRENT_URL)['value'] 
    File "C:\Users\tom\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute 
    self.error_handler.check_response(response) 
    File "C:\Users\tom\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response 
    raise exception_class(message, screen, stacktrace, value['alert'].get('text')) 
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier. 
<super: <class 'WebDriverException'>, <UnexpectedAlertPresentException object>> 

是誤差說行current_url = driver.current_url是觸發錯誤的一個或者是它的下一行?

回答

2

當您使用WebDriver實例的.current_url屬性時,會發送GET_CURRENT_URL webdriver命令,這會在您的情況下觸發錯誤。會發生什麼情況是,當前打開的網頁由於存在警報而不是當前的頂級瀏覽上下文,並且根據specification,它應該並且因錯誤而失敗。

換句話說,當打開主動警報時,無法檢索當前URL。

+0

我想我遵循,所以它不是錯誤的get_current_url,它只是它突出顯示錯誤。所以我想我需要看看導致警報存在 – fightstarr20

+1

@ fightstarr20是的,錯誤發生在'current_url = driver.current_url'行。您應該查看爲什麼此時顯示警報。 – alecxe

+0

它是一個奇怪的,我實際上沒有看到瀏覽器中的錯誤。我可以看到任務欄中的瀏覽器標籤呈藍色閃爍,通常會顯示錯誤或警報,但沒有任何內容 – fightstarr20