Selenium-Python: interact with system modal dialogs

后端 未结 2 1234
既然无缘
既然无缘 2021-01-23 06:00

I am running an app in the browser; and for some actions I was able to simulate actions with keystrokes; but I have a peculiar problem: some actions in my app cause system promp

2条回答
  •  逝去的感伤
    2021-01-23 06:52

    You could make usage of the Selenium methods to check current window and move to another one:

    You can use

    driver.window_handles
    

    to find a list of window handles and after try to switch using following methods (selenium documentation).

    • driver.switch_to_alert()
    • driver.switch_to.active_element
    • driver.switch_to.default_content
    • driver.switch_to.window

    Since the application you work on, seems to respond to Selenium commands here it is a working example about opening a popup window, switching selenium scope on it, extract data and close the popup. The process is repeated for all the products:

    for item in driver.find_elements_by_class_name("products"):
        item.click() # clicking on item activate a popup
        driver.switch_to_alert() #switch to new window
        # Get data
        driver.find_elements_by_css_selector(".ui-dialog-titlebar-close.ui-corner-all")[0].click() #close window
    

提交回复
热议问题