Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get userAgent information in Selenium Web driver

Tags:

java

selenium

I'm trying to get user-agent information for browsers in selenium,java.I tried "HttpServletRequest "and find a method like as below.Which parameter should I give for "HttpServletRequest request"? is it url?

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

Also ,is there anyway to get user-agent in selenium like as javascript? Thanx.

like image 561
laura Avatar asked Apr 05 '17 11:04

laura


1 Answers

String userAgent = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
like image 128
Sébastien Temprado Avatar answered Sep 27 '22 20:09

Sébastien Temprado