How to open devtools and keep the focus on console as default #2066
Answered
by
mdmintz
hiyamandal
asked this question in
Q&A
-
Hello, For a test, I need the devtools to be always open and view the console tab. At the end of the test, I need to print the logs.
Can anyone please help me how to
|
Beta Was this translation helpful? Give feedback.
Answered by
mdmintz
Sep 6, 2023
Replies: 1 comment 3 replies
-
Hello, For 1: Add For 2: There are methods for that: (See the example test: SeleniumBase/examples/test_console_logging.py) self.start_recording_console_logs()
"""
Starts recording console logs. Logs are saved to: "console.logs".
To get those logs later, call "self.get_recorded_console_logs()".
If navigating to a new page, then the current recorded logs will be
lost, and you'll have to call start_recording_console_logs() again.
# Link1: https://stackoverflow.com/a/19846113/7058266
# Link2: https://stackoverflow.com/a/74196986/7058266
"""
self.console_log_string(string)
"""
Log a string to the Web Browser's Console.
Example:
self.console_log_string("Hello World!")
"""
self.console_log_script(script)
"""
Log output of JavaScript to the Web Browser's Console.
Example:
self.console_log_script('document.querySelector("h2").textContent')
"""
self.get_recorded_console_logs()
"""
Returns console logs recorded after "start_recording_console_logs()".
""" |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
mdmintz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
For 1: Add
--devtools
as a pytest command-line option to open devtools with the browser. More info here.For 2: There are methods for that: (See the example test: SeleniumBase/examples/test_console_logging.py)