How to get user information in Selenium web driver

I am trying to get user agent information for browsers in selenium, java.I tried "HttpServletRequest" and found a way as shown below. Which parameter should be specified for the "HttpServletRequest request"? is it url?

 private String getUserAgent(HttpServletRequest request) {
        return request.getHeader("user-agent");
    }

Also, is there anyway to get a user agent in selenium, like javascript for example? Thanx.

+4
source share
1 answer
String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
+7
source

Source: https://habr.com/ru/post/1674080/


All Articles