1

I need to automate where We are sending data which is available on console in real time. Automation test can be to check that data is triggering or data format is correct which is being sent. I can manually check this on console but there are lots of things to check and need to automate the process. Is there any method in selenium which we can utilize to interact with console data.

    2 Answers 2

    1

    Here's a complete example of using selenium (Python) to write to the console logs and to read from them:

    """Record console logs to: "console.logs".""" driver.execute_script( """ console.stdlog = console.log.bind(console); console.logs = []; console.log = function(){ console.logs.push(Array.from(arguments)); console.stdlog.apply(console, arguments); } """ ) """Log a string to the Console (after running the top script)""" driver.execute_script("""console.log(`%s`);""" % string) """Log output of JavaScript to the Console (after running the top script)""" driver.execute_script("""console.log(%s);""" % script) """Get console logs that were recorded above into "console.logs".""" driver.execute_script("return console.logs;") 

    Reference 1: https://stackoverflow.com/a/19846113/7058266

    Reference 2: https://stackoverflow.com/a/74196986/7058266

      0

      You can use driver.manage().logs().get. You also need to configure the loggingPreferences to log normal console.log calls, rather than just more severe error logs.

      0

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.