Python click button on alert

前端 未结 3 489
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:41

    A couple of points here :

    • switch_to_alert had been deprecated so we have to mandatory use switch_to().alert()
    • Seems to me a purely timing issue. Hence we need to induce ExplicitWait i.e. WebDriverWait with expected_conditions clause set to alert_is_present as follows :

      from selenium.webdriver.support import expected_conditions as EC
      #code block
      self.chrome_session.find_element_by_xpath("//input[@value='Accept']").click()
      WebDriverWait(self.chrome_session, 10).until(EC.alert_is_present)
      self.chrome_session.switch_to().alert().accept()
      print("Accepted work order {0} at {1}.".format(link_text, datetime.datetime.now()))
      

提交回复
热议问题