You can use logs to track the progress of your scripts and to better understand what is happening while the script is executing.
Print Statements
The simplest way to log messages is with print statements. You can use them to inspect objects or to determine where an issue is located.
For example, you can determine whether an element was selected on a page by displaying the contents of the object:
elem = driver.find_element_by_id("wiki-content")
print(elem)
PY
If the script results are incomplete, you can use a series of print statements to pinpoint where the problem might have occurred:
print("Getting the web page 'appdynamics.com'.")
driver.get("http://docs.appdynamics.com")
print("Getting the content for the container with the ID 'wiki-content'.")
elem = driver.find_element_by_id("wiki-content")
element = driver.find_element_by_xpath("//select[@name='name']")
all_options = element.find_elements_by_tag_name("option")
for option in all_options:
print("Value is: %s" % option.get_attribute("value"))
option.click()
PY
Logging Package
You can import the logging
package to log different types of error messages.
To import the logging
package and set the log level to DEBUG
:
import logging
logging.getLogger().setLevel(logging.DEBUG)
PY
Once you have imported the logging
package, you can generate different types of logs:
print('Starting the monitoring test')
pageUrl = "https://www.appdynamics.com"
driver.get(pageUrl)logging.info("info message")
logging.debug("Debug message")
logging.warning("Warning message")
logging.error("error message")print('Landed on page successfully!')
PY
The different types of errors are then color-coded in the waterfall of the Session Details dialog.

The script output will label the different log messages by the severity as shown below.
