@@ -625,14 +625,32 @@ def get_logs(self):
625625 warnings .warn ("get_logs always return None with webdrivers other than Chrome" )
626626 return None
627627
628- def reset_log_timestamp (self ):
629- """reset_log_timestamp only work with chrome webdriver ."""
628+ def clear_log (self ):
629+ """Clear browser console logs. Chrome only ."""
630630 if self ._browser == "chrome" :
631- # Flush any existing logs
631+ # Flush logs via Selenium API
632+ self .driver .get_log ("browser" )
633+ # Try to clear via CDP as well
634+ if hasattr (self .driver , "execute_cdp_cmd" ):
635+ try :
636+ self .driver .execute_cdp_cmd ("Log.enable" , {})
637+ self .driver .execute_cdp_cmd ("Log.clear" , {})
638+ except Exception : # pylint: disable=broad-exception-caught
639+ pass
640+ try :
641+ self .driver .execute_cdp_cmd ("Console.enable" , {})
642+ self .driver .execute_cdp_cmd ("Console.clearMessages" , {})
643+ except Exception : # pylint: disable=broad-exception-caught
644+ pass
645+ # Flush again after CDP clear
632646 self .driver .get_log ("browser" )
633- # Set timestamp to now so all previous logs are filtered out
647+ # Reset timestamp
634648 self ._last_ts = int (time .time () * 1000 )
635649
650+ def reset_log_timestamp (self ):
651+ """reset_log_timestamp only work with chrome webdriver."""
652+ self .clear_log ()
653+
636654 @property
637655 def driver (self ):
638656 """Expose the selenium webdriver as fixture property."""
0 commit comments