The main methods are scanning for known flaws and misconfigurations, static analysis of source code, dynamic testing of running applications, fuzzing, software composition analysis of the libraries that you use and manual review. Each finds different things.
Detection tells you a weakness may exist. It does not tell you that it is real, reachable or exploited. Scanners produce false positives when they guess from a version string, and false negatives when a flaw is new or unusual, so results need to be checked.
In AI-based detection, the same issue shows up as a model reporting a problem that is not there, or missing one that is.
Combine several methods, scan on a schedule and after major changes, send findings to the system owner, validate them before urgent work is started and track how many are false positives so that you can tune the tools.