Zaheer Udeen Babar
Zaheer Udeen Babar

Reputation: 152

Unable to click button programatically in UIWebView (Webpage)

I am trying to programatically click on a single button on a webpage in UIWebView using

NSString *jsStat = @"document.getElementsByName('btn btn-info')   [0].click()";
[webView stringByEvaluatingJavaScriptFromString:jsStat];

but the button has not been clicked programatically. My button Class name is "btn btn-info" and button's properties are

<input type="submit" value="Click Me" class="btn btn-info">

and complete page is

<form action="https:www.googleabc.com"post">
<input type=hidden name=ID value="myvalue" /><input type=Hidden name=Style value=STL:18/>
<input type="submit" value="Click Me" class="btn btn-info">

Am i missing something here? or there is any better solution than this?

Upvotes: 2

Views: 304

Answers (1)

Orkhan Alikhanov
Orkhan Alikhanov

Reputation: 10050

It should be getElementsByClassName not getElementsByName:

document.getElementsByClassName('btn btn-info')[0].click()

Working example:

document.getElementsByClassName('btn btn-info')[0].click()
<input type="submit" value="Click Me" class="btn btn-info" onClick="console.log('Clicked!')">

Upvotes: 2

Related Questions