2

I am trying to track down an error in Python Selenium. The error message is..

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>>

Is the error saying that the line current_url = driver.current_url is the one that is triggering the error or is it the next line?

1 Answer 1

2

When you use .current_url property of a WebDriver instance, a GET_CURRENT_URL webdriver command is sent, which is triggering an error in your case. What happens is, the currently opened web-page is not the current top-level browsing context because of the alert being present, and, according to the specification, it should and fails with an error.

In other words, current URL cannot be retrieved when there is an opened active alert.

Sign up to request clarification or add additional context in comments.

4 Comments

I think I follow, so its not the get_current_url that is the error, it's just that it's highlighting the error. So I guess I need to look is causing the alert to be present
@fightstarr20 yeah, the error happens on the current_url = driver.current_url line. You should look into why there is an alert shown at this moment.
Its a strange one, I don't actually see an error in the browser. I can see the browser tab in the taskbar flashing blue which would normally indicate an error or alert but there is nothing there
@fightstarr20 what if you would try taking a screenshot before getting the current_url? Try putting driver.save_screenshot("test.png") right before the current_url = driver.current_url line. What do you see on the image?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.