TL;DR: I was curious about this and was starting an answer. Then went out of town.
I'm not trying to poach points or anything from @Ni. As he points out, get
and execute_script
call self.execute
, which--in turn--calls a method from the Command
class. For example, Command.GET
or Command.EXECUTE_SCRIPT
. And that's where the trail went cold for me...
the source code
https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/remote/webdriver.py
def get(self, url):
"""
Loads a web page in the current browser session.
"""
self.execute(Command.GET, {'url': url})
and
def execute_script(self, script, *args):
"""
Synchronously Executes JavaScript in the current window/frame.
:Args:
- script: The JavaScript to execute.
- \*args: Any applicable arguments for your JavaScript.
:Usage:
driver.execute_script('return document.title;')
"""
converted_args = list(args)
command = None
if self.w3c:
command = Command.W3C_EXECUTE_SCRIPT
else:
command = Command.EXECUTE_SCRIPT
return self.execute(command, {
'script': script,
'args': converted_args})['value']
which points to
https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/remote/command.py
class Command(object):
"""
Defines constants for the standard WebDriver commands.
While these constants have no meaning in and of themselves, they are
used to marshal commands through a service that implements WebDriver's
remote wire protocol:
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
"""
and
https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/remote/remote_connection.py#L142 shows a private method called self._commands
, which is a dictionary containing commands that mirror the syntax seen in ..remote/webdriver.py
For example: Command.GET: ('POST', '/session/$sessionId/url')
vs. self.execute(Command.GET, {'url': url})
The endpoints in self._commands
correspond to the https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-reference, so this is the service "used to marshal commands" (?) or part of it...
(ruby equiv: https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/remote/commands.rb)
url
in a complex manner asjavascript: window.location.href = '{}'".format(url)
where you have the much proven and robustget("{}".format(url))
? What is your exact usecase? – Rosina