如何使用Python/Selenium与Chrome弹出的USB连接窗口交互?

huangapple go评论70阅读模式
英文:

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

问题

我正在使用Python、Selenium、Appium和Behave/Gherkin开发一个测试自动化框架。

我正在开发一个需要与Web应用程序配对的设备的测试。具体来说,Web应用程序已在Chrome浏览器中打开,一旦通过USB连接到PC,Chrome浏览器会识别设备并显示弹出窗口。

我需要使用代码模拟设备的选择,然后点击"Pair"按钮,以便将设备与Web应用程序配对。

我应该如何与它进行交互?

我不想使用键盘模拟,因为这不是一个好的解决方案。

你能帮助我吗?

我找到了一些关于使用pyautogui进行键盘模拟的内容,例如:

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

还有一些关于WebUSB API的内容,但我不确定它是否适用于将设备连接到浏览器。

链接

英文:

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?
如何使用Python/Selenium与Chrome弹出的USB连接窗口交互?
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

答案1

得分: 1

以下是翻译好的部分:

"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"

英文:

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

huangapple
  • 本文由 发表于 2023年6月29日 18:33:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580213.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定