2

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?

1 Answer 1

2

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!')">

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.