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
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":
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:
but below approach is much better:
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.
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.
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.