I would like to know if it’s possible to have different option for the applescript set link.text.
I have the following script:
set link_text to "abc"
but the page I running it from, something has different ways to write abc, for example it is “abc d” or “a bcd”, so I was wondering if there was a way to say:
This is the actual script which I am trying to modify:
set link_text to "abc"
tell application "Safari"
activate
-- wait until page loaded
if my page_loaded(20) is false then error numner - 128
-- get number of links
set num_links to (do JavaScript "document.links.length" in document 1)
-- find the link
set c to num_links - 1
set this_link to ""
set f to false
repeat with i from 0 to c
set this_link to do JavaScript "document.links[" & i & "].text" in document 1
if this_link is link_text then
set f to true
exit repeat
end if
end repeat
if f then -- link text found
-- get the url and open the link url
set link_url to do JavaScript "document.links[" & i & "].href" in document 1
open location link_url -- opens in new page
else
display dialog "Link \"" & link_text & "\" not found."
end if
end tell
--
on page_loaded(timeout_value)
delay 2
repeat with i from 1 to the timeout_value
tell application "Safari"
if (do JavaScript "document.readyState" in document 1) is "complete" then
return true
else if i is the timeout_value then
return false
else
delay 1
end if
end tell
end repeat
return false
end page_loaded