How Do I Automate a Safari click with AppleScript without going through JavaScript?
I'm working on a project that automates Safari to run a batch of test scripts. I am using safariwatir to drive the tests. Sometimes, maybe due to some weird JavaScript issues, the scripts fail. For example, a script to click a link will not work because a JavaScript callback is attached to the link, and safariwatir is failing to invoke the JavaScript callback properly. When a user manually clicks the link, the functionality is working as expected.
I looked at the safa开发者_运维问答riwatir implementation and I learned that automating clicks are implemented via JavaScript.
I tried to look at how to use AppleScript to automate a click on a button or a link, but that approach seems brittle because in order to be able to access a button in AppleScript it looks like I have to know it's position in the GUI hierarchy ("do a click on button 3, inside window 1, group 5, scrollbar 6").
I'm thinking if this approach is better, but I'm not sure if it's possible: 1. Given an HTML element's ID, get the corresponding GUI element 2. Simulate a mouseclick on the GUI element obtained from #1
I am almost certain that #1 above is currently not possible. However if it's doable (even if it's not yet implemented in any existing toolkits out there) I'd appreciate pointers on how to do it.
Thanks!
I agree that it's difficult to manually figure out the hierarchy so that you know what to click with applescript. However, if you knew the position of where you want to click then you can perform a click by position instead. I think javascript could help you find the position... once you locate an object you can get its position.
One other issue, sometimes scripting system events to perform clicks doesn't work well either and if you find that's the case here then I'd suggest using another tool to perform the physical clicks. I have developed to command line tool to perform clicks and use it when system events clicks don't work. You will need to know the screen position for this tool to work. Maybe it will help you. You can find that tool here.
精彩评论