Hi guys,
im a noob when it comes to programming. I asked Chatgpt to write me an AppleScript where id like to push a certain button at an opened Page on Chrome.
The Code looks like this:
-- Ersetze hier den XPath des Buttons oder der URL, die du anklicken möchtest
set targetXPath to "//input[@value="Google Suche"]"
-- Schritt 1: Aktives Chrome-Fenster ermitteln
tell application "Google Chrome"
set targetWindow to front window
set targetTab to active tab of targetWindow
set targetTabURL to URL of targetTab
end tell
-- Schritt 2: Aktuelle Seite im Chrome-Fenster laden
tell application "Google Chrome"
tell targetTab
-- Hier kannst du optionale Aktionen ausführen, wie das Aktualisieren der Seite
-- zum Beispiel: reload
-- oder das Ausführen von JavaScript-Code
-- zum Beispiel: execute javascript "alert('Hello World!');"
end tell
end tell
-- Schritt 3: Warten, bis die Seite vollständig geladen ist
tell application "System Events"
tell process "Google Chrome"
-- Warte, bis das Fenster aktiv und geladen ist
repeat while (URL of active tab of front window is not equal to targetTabURL) or (loading of active tab of front window is true)
delay 0.5
end repeat
end tell
end tell
-- Schritt 4: Button oder URL mithilfe von XPath anklicken
tell application "System Events"
tell process "Google Chrome"
set targetElement to first UI element of front tab of front window whose value of attribute "AXXPath" is equal to targetXPath
perform action "AXPress" of targetElement
end tell
end tell
I Copy and pasted it as you can see in the Macro
test .kmmacros (3.8 KB)
Unfortunatly it doesnt work and i dont know why.. Can anyone help?