无法在selenium中找到Chrome的弹出窗口

时间:2016-09-01 13:02:30

标签: python selenium-webdriver popup selenium-chromedriver

在将此标记为重复之前,请阅读以下几点,因为我已尝试了所有可能的解决方案:

  1. 尝试切换到警报并接受它&解雇它。它会受到接受声明的影响。
  2. 尝试将ENTER / RETURN键发送到弹出窗口。什么都没发生
  3. 尝试将ENTER / RETURN键发送到窗口。什么都没发生
  4. 尝试打印浏览器网址而不切换到提醒状态。抛出unexpectedalertpresentexception的例外。
  5. 尝试打印警报文本。返回无。
  6. 抓住异常并尝试打印alert_text,返回none。尝试打印msg,返回弹出文本。
  7. 以下代码:

        browser.get("https://www.cnm.att.com/emfe/QNCreateTicket?reportTbl=0&tblValue=DHEC297003811&stateCodeValue=&serviceidtypeValue=&trunkgrpandmessageValue=&testFocusControlID1=idfield1&tblCktValue=DHEC297003811&searchStringForASE=%25DHEC297003811%25&oorInd=null&ASEState=null&isASE_ADEinEMDB=&isASE_ADEinEMDBNotProvisioned=&aseflow=&adeflow=&isASEinEBTA=&searchStringForEditForASE=S%3A2%3ADHEC297003811&button=&clci=&qnfromscreen=quick+navigate&phone=&isProvForTesting=1&isProvForCCA=1&isProvForIP=0&isProvForPhone=1&fromtransporttfn=yes&transporttfn=&circuit_format=&state=&ccid=&cac=&isValidPhoneForUser=&isPOTSDataFound=&localPhoneInd=&circuitId=")
    Submit_Ticket = browser.find_element_by_xpath('//*[@id="bottomsec"]/center/table/tbody/tr[2]/td[2]/a/img')
    Submit_Ticket.click()
    
    time.sleep(3)
    
    
        try:
            print browser.title
        except UnexpectedAlertPresentException as e:
            print "exception "+repr(e)
            print "msg"+e.msg
            print browser.current_window_handle
            b = browser.switch_to.window(browser.current_window_handle)
            print b
            b.send_keys(Keys.RETURN,Keys.ENTER)
    

    输出:

        exception UnexpectedAlertPresentException()
    msgunexpected alert open: {Alert text : Before submitting this ticket, you must select the following fields:
    
     Trouble Type
     Outage Condition
    Do you have Power to your Equipment
    Authorize Testing
    Service Impact}
      (Session info: chrome=52.0.2743.116)
      (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86)
    CDwindow-be1b9858-ddb0-4470-9c11-5f1420a94c82
    None
    
    Traceback (most recent call last):
      File "C:\Python27\alert checking.py", line 72, in <module>
        b.send_keys(Keys.RETURN,Keys.ENTER)
    AttributeError: 'NoneType' object has no attribute 'send_keys'
    

    Popup Alert

    当我点击弹出窗口时,代码会进一步执行。

    Submit Element

1 个答案:

答案 0 :(得分:0)

通过将Chrome驱动程序升级到版本2.22来解决此问题,之前它是2.21,这在处理javascript弹出窗口方面存在问题。