Execute Javascript in WebView

Hi to everyone this is my first post and I’m really happy that I’ve found this community.
It’s a big help for new ones in ASOC like me.

Here’s my situation.
I have a webView where I open a URL.
I’d like to execute in that webView a javascript to fill a couple of fields to enter in the user’s area of web site.

So how can I execute Javascript in a webView? I tried this:

-- Code to access to mypage in my webView (webViewP)
webViewP's setMainFrameURL_("http://www.mypage.com") 

-- Code to execute javascript
webViewP's stringByEvaluatingJavaScriptFromString_("alert('Javascript executed!!');")

No error compiling. No error executing. But no Javascript!

And I don’t understand why … As I said I’m not an expert so maybe the answer to the question is really simple, but any help?

Thank you

Model: MacBook Pro 2.53
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

I’ve tried two ways, as instructed by the documentation, and they both did not do anything, but there were no errors. I will try some other JavaScript commands.

Even when an alert is put into an HTML file, like this:

<head ONLOAD="alert('JavaScript executed!');" />

and I load the HTML file in the WebView, it still doesn’t show the alert. When I open the page in Safari, however, the alert comes up.

When I added text in paragraph tags it showed up in the WebView.

I would suggest trying other commands. Maybe you aren’t allowed to have user interaction, just like when running AppleScript from Terminal.

Model: Mac Mini
AppleScript: 2.1.2
Browser: Safari 533.20.27
Operating System: Mac OS X (10.7)

I know next-to-nothing about javascript, but your code looks OK. This worked for me:

log webView's stringByEvaluatingJavaScriptFromString_("14*Math.sin(0.3)")

After some reading, it looks like the alert function just tells the current browser to display the said text in it’s operating system’s default alert box. So that being said, I guess those user interaction functions don’t work because it’s not wired into The WebView to display a dialog.

Long story short, maybe use Shane’s method to extract text from the site and display it in an alert via AppleScript.