You can press buttons like you want, but you need to know the name of the application which displayed the notification window. For example, if “Safari” displayed the notification you could do something like this…
tell application "System Events"
tell process "Safari"
click button "Cancel" of window 1
end tell
end tell
If the window has a name at the top of it you could try something like this… or maybe the window has some specific text that you could search for. Whatever it is, find something unique about the window and then just loop through every process and check the windows for that value.
set windowName to "Untitled"
tell application "System Events"
set runningProcesses to every process
repeat with aProcess in runningProcesses
set processWindows to name of windows of aProcess
if processWindows contains windowName then
return "The process for the window is: " & name of aProcess
end if
end repeat
end tell