# Accessing html elements in web viewer

**URL:** <https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886>\
**Category:** General\
**Created:** [January 6, 2020, 7:27am UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886 "2020-01-06T07:27:50Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [January 7, 2020, 8:16am UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/21 "2020-01-07T08:16:38Z")

</div>

We wrote DOM classes previously for MacOS HTMLViewer, but as you now have 5 engines, we prefer to use JavaScript.

You are welcome to download MBS Plugins and try all the methods above.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 7, 2020, 2:54pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/22 "2020-01-07T14:54:48Z")

</div>

[quote=470412:@Guenter Kraemer]So that wont help me at all.

I have a Win Desktop app, with a htmlviewer, and just want to fill the formfields and submit the form.  
In Delphi, I use the document interface, exposed by the browser control, but I cant find something similar in the htmlviewer control.[/quote]

Christian is in error. ExecuteJavaScript is one of the methods of HTMLViewer DESKTOP.

I don’t suspect him of simply trying to sell his stuff. He probably forgot 😉

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 7, 2020, 3:16pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/23 "2020-01-07T15:16:11Z")

</div>

> [@470458:@Michel Bujardet](#):
>
> Christian is in error. ExecuteJavaScript is one of the methods of HTMLViewer DESKTOP.

+1

> [@](#):
>
> I don’t suspect him of simply trying to sell his stuff. He probably forgot 😉

+1

---

<div class="post-metadata">

**Author:** ![Guenter\_Kraemer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/g/35a633/32.png) [@Guenter\_Kraemer](https://forum.xojo.com/u/Guenter_Kraemer)\
**Post date:** [January 7, 2020, 3:30pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/24 "2020-01-07T15:30:40Z")

</div>

This one works

```auto
js = "document.forms[0].elements['your-name'].value=""test only"";"
HTMLViewer1.executejavascript(js)
```

but not the other

```auto
js = "document.getElementByName('your-name').value='test only';"
HTMLViewer1.executejavascript(js)
```

that give me an OELException

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [January 7, 2020, 3:50pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/25 "2020-01-07T15:50:46Z")

</div>

If you [quote=470458:@Michel Bujardet]Christian is in error. ExecuteJavaScript is one of the methods of HTMLViewer DESKTOP.

I don’t suspect him of simply trying to sell his stuff. He probably forgot ;)[/quote]

Sorry. When you search on the documentation page for ExecuteJavaScript, you end up only with the web entry: [ExecuteJavaScript](http://documentation.xojo.com/ExecuteJavaScript)  
But now I found it: [HTMLViewer.ExecuteJavaScript](http://documentation.xojo.com/api/deprecated/htmlviewer.html#htmlviewer-executejavascript)

Still if you need a result, you better try our plugin.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [January 7, 2020, 3:51pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/26 "2020-01-07T15:51:40Z")

</div>

> [@470469:@Guenter Kraemer](#):
>
> document.getElementByName

I think that must be document.getElementsByName and returns an array, so you need the [0] there.  
(in hope that IE supports it)

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [January 7, 2020, 4:19pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/27 "2020-01-07T16:19:11Z")

</div>

[quote=470412:@Guenter Kraemer]So that wont help me at all.

I have a Win Desktop app, with a htmlviewer, and just want to fill the formfields and submit the form.  
In Delphi, I use the document interface, exposed by the browser control, but I cant find something similar in the htmlviewer control.[/quote]  
Do you control the content of the HTMLViewer? By this I mean, did you write the HTML and javascript in the HTMLViewer, or did some unknown person write it?

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [January 7, 2020, 7:10pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/28 "2020-01-07T19:10:43Z")

</div>

[quote=470469:@Guenter Kraemer]js = “document.getElementByName(‘your-name’).value=‘test only’;”  
HTMLViewer1.executejavascript(js)  
that give me an OELException[/quote]

All depends on the structure of the DOM. I had assumed a simple input tag.At any rate, I am glad you found a way by yourself.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:14pm UTC](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886/29 "2021-04-29T16:14:35Z")

</div>



[Previous page](https://forum.xojo.com/t/accessing-html-elements-in-web-viewer/51886.md?page=1)
