New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling driver.stop() throws up selenium exception #82
Comments
Please add exception traceback |
|
whalesong/whalesong/driver_firefox.py Line 162 in cbbbb21
Why is close() called twice ? |
I this this is the root of the problem. |
whalesong/whalesong/driver_firefox.py Line 177 in cbbbb21
I think the exception is because when I explicitly call close() the connection is closed but when the polling driver calls close() it raises an exception since the connection already tore down. |
I think it can be fixed if we check the webdriver status before calling close() . Is there an API for that ? |
Yes, I think we are calling close twice, too. As workaround you could catch exception. |
Beside catching that exception is there a way we can check the status of webdriver status so that we don't land in the exception in the first place ? |
I did this try:
self.driver.quit()
await self.close()
except ConnectionRefusedError:
pass
except Exception as e:
pass |
Is this the correct way ? If it is I will create a pull request |
Well, I don't think it is a good solution, it's a workaround. Good solution must be something more generalist. I think it must be on abstract class, it must avoid to try to stop driver when it is stopping or stopped, or to try to start when it is starting or already started. |
what if I do this try:
if not self._fut_running.done():
await self.close()
except ConnectionRefusedError:
pass
except WebDriverException:
pass
except Exception:
pass |
Do you think it's still a workaround ? |
I mean: this method should be: (https://github.com/alfred82santa/whalesong/blob/master/whalesong/driver.py#L40) async def start_driver(self):
if self._fut_stop is not None:
await self._fut_stop
self._fut_stop = None
if self._fut_start:
await self._fut_start
return
self._fut_start = ensure_future(self._internal_start_driver())
await self._fut_start And this other should be: (https://github.com/alfred82santa/whalesong/blob/master/whalesong/driver.py#L143) async def close(self):
if self._fut_start is not None:
await self._fut_start
else:
return # Not started
if self._fut_stop:
await self._fut_stop
return
self._fut_stop = ensure_future(self._internal_close())
await self._fut_stop
self._fut_start = None Try this change, and if it works I'll approve a PR. |
The problem is the await if self._fut_start is not None:
await self._fut_start It just waits there indefinitely |
If I change the order to self._fut_start = None
self._fut_stop = ensure_future(self._internal_close())
await self._fut_stop your fix works . seems like a race condition. I am not so sure |
Change this: (https://github.com/alfred82santa/whalesong/blob/master/whalesong/driver_firefox.py#L177) try:
await self.close()
except ConnectionRefusedError:
pass by: ensure_future(self.close()) |
Here is my test script
And here the exception
selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection
The text was updated successfully, but these errors were encountered: