python - 在这种情况下,如何使用动作链模拟 Selenium、Python 的击键?
问题描述
当我在 Windows/Mac 上的任意位置按下 CTRL+SHIFT+2 时,我会打开一个弹出的(PhraseExpress)表单。我想在 Selenium 中模仿它。理想情况下,它应该适用于 Windows 和 Mac。现在我尝试使用 send_keys 和 ActionChains 让它在 Windows 上工作。
def open_form() -> None:
"""function to open the corresponding phraseexpress form (with a hotkey)."""
bodyElement = WebDriverWait(driver, 40).until(
EC.element_to_be_clickable((By.TAG_NAME, "body"))) #get a random element to perform send-keys action on.
# create action chain object
actions = ActionChains(driver)
if fullstring == "Note 2":
if platform == "win32": #if on Windows
actions.key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys_to_element(bodyElement, "2").key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform()
#actions.key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys('2').key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform() # I tried this as well
#pyautogui.hotkey('ctrl', 'shift', '2') #This is working but I would like to use the above method instead, hoping it will work on Mac as well. This hotkey does not work on Mac. I think the hotkey is executed in Terminal instead of the OS, hence nothing happens.
print("You opened PhraseExpress for Note 2")
终端中的输出是“您打开了 PhraseExpress for Note 2”,但没有弹出表单。按键不会触发操作系统上的表单。知道可以做什么吗?当 pyautogui.hotkey() 起作用时,为什么此操作不起作用?
解决方案
推荐阅读
- c# - 使用UDP c#发送哈希表
- sql - 用于股票分析的美元加权抽样
- python - 如何使用请求获取 html 代码的注释部分?
- reactjs - 将 WebWoker 与 create-react-app 和 typescript 一起使用
- javascript - 使用 Content-Management-API 在内容空间中创建嵌套条目
- python - 如何知道模型实例是否被其他用户修改
- bash - 我可以使用 GIT_CONFIG 环境变量为所有 git 命令使用配置文件吗
- php - 如何将第二个 Html 表单链接到 php
- mesh - 在 ITK-SNAP 中加载标记图像以进行渲染
- prestashop - 升级 Prestashop 有问题吗?