title: How to set more than one desired capabilities in Selenium using Java?
body: <p>I am trying to launch chrome in mobile emulation mode and also wanted to set user agent before launch happens. I have found ways to do this one at a time but unable to do it both for same instance of chrome.
  Following is my code:</p>
  
  <pre><code>String useragent="Mozilla/5.0 (Windows NT 6.1\\; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 WFBTesting";
      Map&lt;String, String&gt; mobileEmulation = new HashMap&lt;String, String&gt;();
      mobileEmulation.put("deviceName", "Google Nexus 5");
      Map&lt;String, Object&gt; chromeOptions = new HashMap&lt;String, Object&gt;();
      chromeOptions.put("mobileEmulation", mobileEmulation);
  
      ChromeOptions options = new ChromeOptions();
      options.addArguments("--user-agent="+useragent);
      options.addArguments("--test-type");
      options.addArguments("--allow-running-insecure-content");
  
  
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      //capabilities.setCapability(ChromeOptions.CAPABILITY,(chromeOptions));
      capabilities.setCapability(ChromeOptions.CAPABILITY,options);
  
  
      WebDriver driver = new ChromeDriver(capabilities);
  </code></pre>
  
  <p>In above code I can either pass options or chromeOptions in "capabilities.setCapability(ChromeOptions.CAPABILITY,<strong>options</strong>);" but if write two setCapability methods one with options and other with chromeOptions, only one of them is in effect for the launched chrome session and not both. Kindly suggest the best way to set both the capabilities and launch the chrome session.</p>
  
  <p><strong>EDIT</strong>
  As suggested I tried following:
  Thanks @Cyildirim for your response again. I used following code for my script this time: </p>
  
  <pre><code>Map&lt;String, String&gt; mobileEmulation = new HashMap&lt;String, String&gt;();
          mobileEmulation.put("deviceName", "Google Nexus 5");
          Map&lt;String, Object&gt; chromeOptions = new HashMap&lt;String, Object&gt;();
          chromeOptions.put("args", Arrays.asList("user-agent=Mozilla/5.0 (Windows NT 6.1\\; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36 WFBTesting","test-type","allow-running-insecure-content"));
          chromeOptions.put("mobileEmulation", mobileEmulation);DesiredCapabilities capabilities = DesiredCapabilities.chrome();
          capabilities.setCapability(ChromeOptions.CAPABILITY,(chromeOptions));
  </code></pre>
  
  <p>But even using above I cannot get the user profile to set correctly. Only mobile emulation capability is getting set. Can you correct me if I am writing useragent incorrectly in Array? Or any other suggestion to make it work.</p>