0

I have a webview that is displaying a page that looks like a calendar and on that calendar are events that are buttons which can be single or double-clicked - single/double calling a different function. Note: I cannot change the coding of this page. Here is a snippet of a button: <div class="boardpiece clickable" onclick="selectPairing(event, this);" id="sn_18067063" The ID for the button is dynamic - or will always be unknown - so I cannot use it in my coding. The classes of the items I need my clicks to work on, however, are known.

Now, there are only a few classes of buttons here so I can designate what to do for each class if that is a solution. I think I saw a question/answer saying that you may be able to identify the element by an HTML attribute? Something like "If outerHTML contains "boardpiece clickable" Do function "selectPairing" ..." That's my train of thought at least.

Or am I going about this the wrong way? I simply need to call the onclick functions of these elements if the user clicks (taps) on the element. If I were creating the buttons myself, that would be simple. I think I can set a stop function in my onClick so that only the one button is activated since they all have the same class.

~ Dan

Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44
Dan
  • 85
  • 1
  • 9
  • It appears the example question I was referring to where you find by HTML element was for Capybara and not android. [Here](http://stackoverflow.com/questions/14773936/capybara-clicking-a-button-without-an-id) is the question. So, that's probably way off. – Dan Jan 08 '14 at 08:41

1 Answers1

1

If you want to perform any operation on a HTML page inside a web view then you have to modify the code. you need to set onClick event of a button using JavaScript or you have to get element from the HTML page based on the ID.

Raj
  • 496
  • 7
  • 27
  • Well, it is Javascript within the HTML of the loaded webpage. Does that make a difference? What I mean is the onClick event when the button is clicked is within the coding of the button - as you can see from the snippet. – Dan Jan 08 '14 at 08:49
  • is it a offline HTML page or any url loading in web view? – Raj Jan 08 '14 at 08:50
  • It's a website loaded within webview. – Dan Jan 08 '14 at 08:51
  • 1
    ohk sorry friend then in this case you can not set any eventlistner on items inside the web view.if you want to do so then you have to set in HTML code(i.e in website). – Raj Jan 08 '14 at 08:56
  • So you're saying I cannot use the onClickListener within webview without using the button's ID? How can I have the user tap on the calendar event and have the onClick function of the button called then? – Dan Jan 08 '14 at 09:00
  • can you brief me about what do you want to perform? if possible mail me @rajb865@gmail.com – Raj Jan 08 '14 at 09:01
  • Sure. [HERE](http://stackoverflow.com/questions/20810023/android-webview-page-requires-double-clicking-how-to-handle) is the question in detail. Will send you an e-mail, too. – Dan Jan 08 '14 at 09:03
  • I think if you know the ID then use this code `webView.loadUrl("javascript:(function(){document.getElementById('buttonClick').click();})()");` – Raj Jan 08 '14 at 09:04
  • That would be so easy except the ID can never be known. The IDs are different for each event and could be anything within thousands of variables. – Dan Jan 08 '14 at 09:13
  • then it should need to handle using Javascript and HTML. capture double click and single click using JS functions and the perform your desired operation – Raj Jan 08 '14 at 09:18