How to send ESC key to close pop up window using Python and Selenium?

前端 未结 3 1177
南旧
南旧 2020-12-30 03:01

As mentioned, is there a way to send global ESC key to close popup(CSS MODAL Window)? I tried following but did not work:

driver.find_element_by         


        
相关标签:
3条回答
  • 2020-12-30 03:21

    try also this it will go back to the previous driver u had

    driver.back()
    
    0 讨论(0)
  • 2020-12-30 03:24

    You don't need to send keys to the element, you need to press them globally (to browser).

    You can do it via Actions.

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
    

    You can see more info in Webdriver API - 7.2 Action Chains doc

    0 讨论(0)
  • 2020-12-30 03:32

    I code my Selenium Python scripts in the AppRobotic Personal editor, and just insert its Windows macro functionality in between Selenium actions.

    import win32com.client
    x = win32com.client.Dispatch("AppRobotic.API")
    from selenium import webdriver
    
    x.Type("{ESCAPE}")
    
    0 讨论(0)
提交回复
热议问题