I am have a problem with the set var editButton
Getting this error-- System Events got an error: Cant get table 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1 of process "Safari". Invalid index.
I know the elements in the table are available sometime and not others. The purpose of the editButton var is to check and see if that element exists before it tries to click the button. I believe what this error is telling me is that that element {n} does not exist. Any insight as to how to rectify this would be greatly appreciated.
-Blake
Getting this error-- System Events got an error: Cant get table 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1 of process "Safari". Invalid index.
I know the elements in the table are available sometime and not others. The purpose of the editButton var is to check and see if that element exists before it tries to click the button. I believe what this error is telling me is that that element {n} does not exist. Any insight as to how to rectify this would be greatly appreciated.
-Blake
Code:
set mainURL to "https://your site/" as text
set mainLogin to "your username" as text
set mainPword to "your password" as text
--display dialog mainURL
tell application "Safari"
activate
open location mainURL
end tell
delay 3
-- Count number of rows in the table
to countRows()
tell application "System Events"
tell process "Safari"
count (rows of table 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1)
end tell
end tell
end countRows
set rowCount to countRows()
--Number of rows minus the header
set x to rowCount - 1 as integer
--Repeat function
repeat with n from 2 to x
tell application "Safari"
tell application "System Events"
--If this exists then execute process
tell process "Safari" to set editButton to get value of UI element 2 of row 1 of table 1 of UI element 2 of row {n} of table 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
if (exists editButton) then --If link exists
--then click link and click previous page
delay 3
tell process "Safari" to click button 1 of UI element 2 of row 1 of table 1 of UI element 2 of row {n} of table 1 of group 6 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
delay 2
tell process "Safari" to click UI element 2 of group 1 of group 1 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
end if
end tell
end tell
end repeat --End Repeat
tell application "Safari"
tell application "System Events"
delay 3
--Logout of website
tell process "Safari" to click static text 1 of UI element 2 of group 1 of UI element 1 of scroll area 1 of group 1 of group 1 of group 2 of window 1
end tell
quit --Close App
end tell