Invoking Javascript on a webBrowser.Document in C#

Houston, we have a problem! Invoking Javascript on a page through a webbrowser in a C# application.Houston, we have a new problem!

So, I’m working away at this little project, bemoaning the fact that I can’t get posts to populate in the textarea on this particular social site. My login and logout code works well but there’s a problem with the status updates.

This is one of those text boxes that grows when you click it with the mouse or Tab into it. The problem seems to be a Javascript that needs to be invoked properly for the text box to appear. I want to automate posting, I don’t want to use 0Auth and the API and I want this all to run automatically with no need for human interaction.

Here’s the <script> in the <head> of the page.

<script>window.Bootloader && Bootloader.done(["6HM2D"]);</script>

Here’s the way it appears in <textarea> on the page.

onkeydown="window.Bootloader &amp;&amp; Bootloader.loadComponents([&quot;control-textarea&quot;], function() { TextAreaControl.getInstance(this) }.bind(this)); "

I’m not the Javascript guy but it appears that the script is being called with different options to open the text box in response to a key press or a mouse click. I’ve tried simulating a human entering the data. First, I tried just copying the data into the <textarea> element, followed by having the software click the button. This didn’t work. I followed by trying to simulate a MouseDown event but I’m new to C# and I’m not sure I did it properly. I finally used Focus() to get focus on the <textarea> and found that, if I follow it with putting text into the initial box, the box will grow, the text will disappear and I won’t be able to add anything to it.

What are my possible solutions?

As I see it, I have three possible solutions.

  1. Find a way to convince the program that the text area was clicked so it will expand before entering text.
  2. Find a way to bypass it, entering values and attributes to that <textarea> that will negate the need to do all the clicking and entering.
  3. Use HttpWebRequest to bypass the need for interacting with the webBrowser.

I’ve tried 1 but I may have not been executing it properly. I dove blindly into C# with no training because it is so easy for me to read after learning the syntax for C, C++, Java and PHP. I have not been able to find 2, a way to bypass it but I’m not sure what all their code does. That bring us to 3 and I have not studied HttpWebRequest yet, though I can tell you that will be on my list now.

If you, dear friend, can offer some help with this problem, it would be greatly appreciated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s