You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Selenium Webdriver has support for logging that I have found useful for development and debugging purposes. There are two approaches that I know of to enable and create logs:
Enable the creation of a log using a command line switch when the Selenium Webdriver executable is invoked.
Enable the creation of logs using a combination of Capabilities (to enable) and interacting with the Selenium Webdriver using commands COMMAND_GET_LOG and CMD_GET_AVAILABLE_LOG_TYPES.
My recommended approach is 1) above. I was able get the second method to work also, but it appears inconsistent and buggy to me, and not nearly as easy and as effective as approach 1 above. For that reason I will focus on the first method, but will also leave some observations about the second method at the end of this note.
APPROACH 1 - Command Line Switch:
With this approach, a command line switch or argument is passed to Selenium Webdriver when the executable is invoked as in this example (see Chrome Driver Logging):
The argument "--verbose" tells the Selenium to create a comprehensive log of webdriver and browser event information. The "--log-path" argument allows user to specify a path to the log file. Be sure to bracket the path with quotes (Chr(34)) if the path contains spaces.
Once the Selenium Webdriver shuts down, then the user can examine the log file with a text editor.
This method works for Edge and Chrome equally.
In order for this to function easily in TinySeleniumVBA, the WebDriver class must expose a way for user to pass command argument switches as in this example:
Then the serviceArgs parameter should be passed all the way down to the Start method:
shell(driverPath & Port & serviceArgs, AppWinStyle)
I made the above changes to my code version and have used the logging capability successfully to develop Actions functionality and to check browser warnings...
APPROACH 2 - Notes for using Capabilities and WebDriver class commands
Observations:
For both of the commands COMMAND_GET_LOG and CMD_GET_AVAILABLE_LOG_TYPES to work, the following changes need to be made to initCommands sub in WebDriver class:
'CMD_GET_LOG = Array("POST", "/session/$sessionId/log") 'this works
CMD_GET_LOG = Array("POST", "/session/$sessionId/se/log") 'this works
'CMD_GET_AVAILABLE_LOG_TYPES = Array("GET", "/session/$sessionId/log/types") 'this doesn't work
CMD_GET_AVAILABLE_LOG_TYPES = Array("GET", "/session/$sessionId/se/log/types") 'this works
Then to enable logging, the Capabilities object should be set to the following for Edge:
In both cases above, we are asking for two loggers - one for the browser and the other for the driver. The "ALL" specifies the level (or verbose-ness) of the logging. There are different levels: ALL, INFO, DEBUG, WARNING, SEVERE, OFF etc. My experience is that setting the level to something other than "ALL" did not always work as expected. For example, setting the level for the driver log to DEBUG, INFO, or ALL appears to result in logging at ALL level! There were other unexplained curiosities as well, but I won't elaborate these unless there is interest...
In Selenium, there are other logger types: Performance, Client, and Server. I was not able to enable Client and Server logging but was able to get Performance logging to work. My understanding is that Performance logging is used in website development and so may not be relevant to most applications of this software.
The way one retrieves info from the loggers, if enabled, is to add functions to the WebDriver class like this below:
Public Function GetLogTypes(Optional ByVal sessionId As String = vbNullString) As Variant()
Dim data As New Dictionary, resp As Collection
If sessionId <> vbNullString Then
data.Add "sessionId", sessionId
End If
Set resp = Execute(CMD_GET_AVAILABLE_LOG_TYPES, data)("value") 'returns a 1-based collection
ReDim Ret(0 To resp.Count - 1)
For i = 0 To resp.Count - 1
Ret(i) = resp.Item(i + 1)
Next i
GetLogTypes = Ret
End Function
Public Function GetLog(ByVal logtype As String, Optional ByVal sessionId As String = vbNullString) As String
Dim data As New Dictionary, ltarray(), logtypefound as boolean
ltarray = GetLogTypes(sessionId)
logtypefound = False
For i = 0 To UBound(ltarray)
If logtype = ltarray(i) Then
logtypefound = True
Exit For
End If
Next i
If logtypefound Then
If sessionId <> vbNullString Then
data.Add "sessionId", sessionId
End If
data.Add "type", logtype
Dim resp As Collection
Set resp = Execute(CMD_GET_LOG, data)("value") '"value" returns a collection
'return a Json string
GetLog = JsonConverter.ConvertToJson(resp, 4)
Else
GetLog = ""
End If
End Function
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The Selenium Webdriver has support for logging that I have found useful for development and debugging purposes. There are two approaches that I know of to enable and create logs:
My recommended approach is 1) above. I was able get the second method to work also, but it appears inconsistent and buggy to me, and not nearly as easy and as effective as approach 1 above. For that reason I will focus on the first method, but will also leave some observations about the second method at the end of this note.
APPROACH 1 - Command Line Switch:
With this approach, a command line switch or argument is passed to Selenium Webdriver when the executable is invoked as in this example (see Chrome Driver Logging):
The argument "--verbose" tells the Selenium to create a comprehensive log of webdriver and browser event information. The "--log-path" argument allows user to specify a path to the log file. Be sure to bracket the path with quotes (Chr(34)) if the path contains spaces.
Once the Selenium Webdriver shuts down, then the user can examine the log file with a text editor.
This method works for Edge and Chrome equally.
In order for this to function easily in TinySeleniumVBA, the WebDriver class must expose a way for user to pass command argument switches as in this example:
Then the serviceArgs parameter should be passed all the way down to the Start method:
I made the above changes to my code version and have used the logging capability successfully to develop Actions functionality and to check browser warnings...
APPROACH 2 - Notes for using Capabilities and WebDriver class commands
Observations:
For both of the commands COMMAND_GET_LOG and CMD_GET_AVAILABLE_LOG_TYPES to work, the following changes need to be made to initCommands sub in WebDriver class:
Then to enable logging, the Capabilities object should be set to the following for Edge:
And for Chrome:
In both cases above, we are asking for two loggers - one for the browser and the other for the driver. The "ALL" specifies the level (or verbose-ness) of the logging. There are different levels: ALL, INFO, DEBUG, WARNING, SEVERE, OFF etc. My experience is that setting the level to something other than "ALL" did not always work as expected. For example, setting the level for the driver log to DEBUG, INFO, or ALL appears to result in logging at ALL level! There were other unexplained curiosities as well, but I won't elaborate these unless there is interest...
In Selenium, there are other logger types: Performance, Client, and Server. I was not able to enable Client and Server logging but was able to get Performance logging to work. My understanding is that Performance logging is used in website development and so may not be relevant to most applications of this software.
The way one retrieves info from the loggers, if enabled, is to add functions to the WebDriver class like this below:
Beta Was this translation helpful? Give feedback.
All reactions