skip to Main Content

Error:
[3528:3760:0205/072321.889:ERROR:device_event_log_impl.cc(192)] [07:23:21.489] USB: usb_service_win.cc:105 SetupDiGetDeviceProperty({{A45C254E-DF1C-4EFD-8020-67D146A850E0}, 6}) failed: Element not found. (0x490)

I’m running my application in AWS EC2 Instance and in local it runs fine but not in server.

I’m facing above errors in Console as logs and my application is stuck at this point.

Dictionary<string, object> prefs = new Dictionary<string, object>
            {
                { "webusb_allow_devices", false }

            };

            browserOptions.AddAdditionalCapability("prefs", prefs);

if i use prefs it gives error like
there is already an option for the prefs capabilty.

Then I tried this

Dictionary<string, object> prefs = new Dictionary<string, object>
            {
                { "webusb_allow_devices", false }

            };

            browserOptions.AddAdditionalCapability("chromeOptions", prefs);

Then I got this error:
OpenQA.Selenium.WebDriverException: unknown error: cannot parse capability: goog:chromeOptions

2

Answers


  1. Analyzing your error code, the error stated there is already an option for the "prefs" capability when trying to add the "prefs" capability, it suggests that the "prefs" capability might already be set elsewhere in your code or that it’s not the correct approach for modifying Chrome options in your Selenium setup.

    Therefore, you can directly add the Chrome options using the "chromeOptions" capability instead of trying to add them through the "prefs" capability. The following example shows how you can modify your code and using the "chromeOptions":

    // Create a ChromeOptions instance
    ChromeOptions options = new ChromeOptions();
    
    // Add the '--disable-webusb' argument directly to the Chrome options
    options.AddArgument("--disable-webusb");
    
    // Pass the Chrome options to the browser options
    browserOptions.AddAdditionalCapability("chromeOptions", options);
    

    By directly adding the –disable-webusb argument to the Chrome options and passing them using the "chromeOptions" capability, you should be able to disable the WEB USB feature in ChromeDriver Selenium in C# without encountering the error related to the "prefs" capability.

    Also, thinking about setting the excludeSwitches capability that might really work like:

    ChromeOptions options = new ChromeOptions();
            options.AddExcludedArgument("enable-features=WebUSB");
    

    but below approach is much better:

    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    
    class Program
    {
        static void Main(string[] args)
        {
            // Step 1: Create Chrome options and add the --disable-webusb argument
            ChromeOptions options = new ChromeOptions();
            options.AddArgument("--disable-webusb");
    
            // Step 2: Create a Chrome driver instance with the Chrome options
            ChromeDriver driver = new ChromeDriver(options);
    
            // Now you can use the Chrome driver instance to interact with your application
            // For example, you can navigate to a URL:
            driver.Navigate().GoToUrl("https://example.com");
    
            // Remember to close the driver when you're done
            driver.Quit();
        }
    }
    

    This will make sure that Chrome options are correctly configured to disable WEB USB and passed to the ChromeDriver instance, resolving the issue you have encountered.

    Login or Signup to reply.
  2. I don’t know the reason the answer is marked down, without comment. I believe there are more than two ways of solving any issues and there might be another approach worth trying. Sometimes, the error might not be directly related to the capability itself but rather how it’s being passed or interpreted by the Selenium WebDriver.

    Try this code sample: Ensure you modify the URL to the URL you would like to navigate.

    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    
    class Program
    {
    
    
     static void Main(string[] args)
        {
            // Step 1: Create Chrome options
            ChromeOptions options = new ChromeOptions();
    
            // Step 2: Add arguments to disable webusb
            options.AddArgument("--disable-webusb");
    
            // Step 3: Create the dictionary to store the Chrome preferences
            var prefs = new Dictionary<string, object>
            {
                {"profile.default_content_setting_values.webusb", 1} // 1 to disable, 2 to enable
            };
    
            // Step 4: Add the preferences to the Chrome options
            options.AddAdditionalCapability("prefs", prefs);
    
            // Step 5: Create a Chrome driver instance with the Chrome options
            ChromeDriver driver = new ChromeDriver(options);
    
            // Now you can use the Chrome driver instance to interact with your application
            // For example, you can navigate to a URL:
            driver.Navigate().GoToUrl("https://example.com");
    
            // Remember to close the driver when you're done
            driver.Quit();
        }
    }
    

    The above is a C# code.

    I have combined the disabling of WebUSB via command-line argument (–disable-webusb) and setting the preference through the prefs capability. This is to make sure both approaches are taken to disable WebUSB, it might help in cases where the error is related to capability interpretation or interaction.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search