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)
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()
You can import the
logging package to log different types of error messages.
To import the
Once you have imported the
logging package, you can generate different types of logs:
print("This is a print statement.") logging.info("This is an info message") logging.warn("This is a warning message") logging.debug("This is a debug message") logging.error("This is an error message")
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.