0

When I press the CTRL+SHIFT+2 anywhere on Windows/Mac I open a (PhraseExpress) form that pops up. I would like to mimic that in Selenium. Ideally it should work on both Windows and Mac. Now I try to get it to work on Windows with send_keys and ActionChains.

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

The output in terminal is "You opened PhraseExpress for Note 2" but the form does not pop up. The key presses does not trigger the form on the OS. Any idea what can be done? Why is this action not working when pyautogui.hotkey() does work?

AppCreator
  • 241
  • 1
  • 2
  • 11
  • Sorry if this is not helpful but why do you need to use Selenium to open that form? Why not start PhraseExpress with, say, an AutoIT script fired up from your python script? – Alichino Sep 22 '21 at 07:49
  • The script needs to work on both Mac and Windows. Can you tell me more about how I can mimic the keypresses (that opens the PhraseExpress form)? As you can see I tried pyautogui but it does not work on Mac since the window does not have focus. – AppCreator Sep 22 '21 at 07:58
  • Hmm just to make sure - do you absolutely NEED to open PhraseExpress with the keystrokes? If not, then perhaps first do a check which OS is running, and then start the application via some other way, specific to the OS (eg. AutoIT for Win, not sure about Mac though)...? -- EDIT: maybe this? --> https://stackoverflow.com/questions/28845242/how-to-open-an-application-in-mac-os-using-python – Alichino Sep 22 '21 at 08:12

0 Answers0