pythonselenium-webdriverusbwebusb

How can i interact with Chrome pop-up for USB connection in Python/Selenium?


i'm developing a Test Automation framework in Python using Selenium, Appium and Behave/Gherkin.

I'm developing the test of a device that is needed to be paired to Web App. In particular, the Web App has been opened with Chrome browser and once the device is plugged-in via USB to PC, Chrome browser recognize it and shows the pop-up.

I need to simulate using code the selection of device and then click on Pair, in order to pair the device to web app.

How can i interact with it? USB pop-up chrome I'm not looking for to use the keyboard simulation because it isn't a good solution.

Could you please help me in this?

I found something about keyboard simulation using pyautogui such as:

def keyboard_simulation(username, password):
    time.sleep(2)
    pyautogui.typewrite(username)
    pyautogui.press('tab')
    pyautogui.typewrite(password)
    pyautogui.press('enter')

and something about WebUSB API but about it, i can't understand if it useful to connect devices to browser. text


Solution

  • Automation of the permission prompt shown by navigator.usb.requestDevice() is not currently supported by the Chrome DevTools Protocol and therefore isn't supported by Selenium.

    To help the team prioritize this feature please add a comment to this Chromium issue asking for support for automating the WebUSB permission prompt:

    https://bugs.chromium.org/p/chromium/issues/detail?id=1142566