Changing the user agent using selenium webdriver in Java

后端 未结 3 1505
再見小時候
再見小時候 2021-02-06 11:36

Can someone pls tell me how to switch the user agent using webdriver in Java? I tried below, but getting errors.

FirefoxProfile ffp = new FirefoxProfile(); 
ffp.         


        
3条回答
  •  误落风尘
    2021-02-06 12:01

    I needed to do it for Chrome, and needed to set a specific string (not fitting as platform, browser or version) for Googlebot.

        // import org.openqa.selenium.chrome.ChromeOptions;
    
        ChromeOptions options = new ChromeOptions();
        options.addArguments("user-agent=\"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\"");
        new ChromeDriver(options);
    

提交回复
热议问题