2017-06-04 66 views

回答

0

這是訣竅的代碼。我有問題沒有保存。不知道爲什麼,但後來我意識到可能有些情況下我仍然想要保存現有的文檔。

var untitledWindow = app.windows["Untitled"] 
    if untitledWindow.exists { 
     untitledWindow.typeKey("w", modifierFlags:.command) 
     //untitledWindow.buttons[XCUIIdentifierCloseWindow].click() should work too 
     if untitledWindow.buttons["Save"].exists{ 
      untitledWindow.buttons["Save"].click() 
     } 
     if untitledWindow.buttons["Replace"].exists { 
      untitledWindow.buttons["Replace"].click() 
     } 
    }