Python click button on alert

前端 未结 3 487
Happy的楠姐
Happy的楠姐 2020-12-21 14:59

I am new to python, but need to modify code created by someone else. I am not able to post the full code, but I posted most of it below:

from bs4 import Beau         


        
3条回答
  •  太阳男子
    2020-12-21 15:34

    I dont know if the below code will help you, at one point I faced the same problem and ended up waiting for an alert and then accepting the alert, worked for me.

    from selenium.common.exceptions import NoAlertPresentException,
    
       def wait_for_alert(self):
    
            for i in range(50):
                try:
                    alert = chrome_session.switch_to.alert
                    if alert.text:
                       break
                except NoAlertPresentException:
                  pass
                time.sleep(.25)
            else:
                raise NoAlertPresentException("Alert visibility timed out")
        return alert
    
    wait_for_alert().accept()
    

提交回复
热议问题