TL; DR: Мне было любопытно, и я начал отвечать.Затем уехал из города.
Я не пытаюсь переманивать очки или что-то из @Ni.Как он указывает, get
и execute_script
вызывают self.execute
, что, в свою очередь, вызывает метод из класса Command
.Например, Command.GET
или Command.EXECUTE_SCRIPT
.И вот тут след для меня остыл ...
исходный код
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})
и
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']
, который указывает на
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
"""
и
https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/remote/remote_connection.py#L142 показывает закрытый метод с именем self._commands
, который представляет собой словарь, содержащийкоманды, которые отражают синтаксис, видимый в ..remote/webdriver.py
Например: Command.GET: ('POST', '/session/$sessionId/url')
против self.execute(Command.GET, {'url': url})
Конечные точки в self._commands
соответствуют https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-reference,, поэтому этоСлужба "используется для маршалинга команд" (?) или ее часть ...
(ruby эквивалент: https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/remote/commands.rb)