所以,现在我的代码点击了safari中的textarea然后它使用击键添加了一个单词,但是我想知道是否有办法找到并替换该区域中的单词并且还有一种方法来替换突出显示没有按键的单词?
当前代码: 对不起它的格式非常糟糕,因为我对Applecript非常糟糕
to clickClassName(theClassName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementnum & "].click();" in document 1
end tell
end clickClassName
to clickID(theId)
tell application "Safari"
do JavaScript "document.getElementById('" & theId & "').click();" in document 1
end tell
end clickID -- All the code up to this point did is allow me to click on IDs and classes in safari.
tell application "Safari" to activate
tell application "System Events"
tell application "Safari"
tell window 1
set current tab to (make new tab with properties {URL:"https://en.wikipedia.org/w/index.php? title=User:USERNAMEHERE/sandbox&action=edit"})
end tell
end tell
end tell
delay 2 -- All the code up to this point from the last comment did is open a new tab in safari.
repeat 5 times
set randomlist to {"1","2","3","4"} -- List of numbers that will be randomly selected and put in the texarea
set randomword to some item of randomlist
clickClassName("tool-button wikiEditor-toolbar-spritedButton", 0) -- This clicks the bold button on the sandbox page
tell application "System Events"
tell process "Safari"
keystroke randomword -- Uses keystroke to put replace the text inside the bold formatting area
end tell
end tell
delay 1
clickID("wpSave") -- Clicks save
delay 2
tell application "Safari" to set the URL of the front document to "https://en.wikipedia.org/w/index.php? title=User:USERNAMEHERE/sandbox&action=edit" -- Goes back to sandbox and repeats the process
delay 2
end repeat
如果您想对此进行测试,请在链接中输入您的维基百科用户名并登录您的帐户。几乎是一个维基百科机器人,它只会把东西放在我的维基百科沙箱中