-1

I would like to write simple scripts which after I have already opened site ( I dont wanna script to open it) press two buttons and insert data in comment section after pressing f.ex. 'g' button. I am completly new in that kind of programming so any help will be nice( also link to good tutorials).

 webBrowser1.Document.GetElementById("User").SetAttribute("value", textBox1.Text);
        webBrowser1.Document.GetElementById("but").InvokeMember("click");

I am aware of those 2 functions i will use but how to instantiate them on already opened page by pressing a button? (If thats important deafult used browser is opera).

8
  • 1
    Possible duplicate of Inject Javascript code into a web page Commented Jan 3, 2017 at 22:46
  • 1
    This has absolutely nothing to do with C#. You're talking about javascript. I've fixed your tags for you. Commented Jan 3, 2017 at 22:47
  • I have no idea if it is or its not. I heard it may be done in c# thats why I prefer that language. Commented Jan 3, 2017 at 22:52
  • Your question is far too broad to answer adequately. For example, do you need to see the resultant page or is it just for submission? More about what you're actually trying to do (instead of asking how to accomplish the solution you've concocted) would help your case. People tend to go right to something negative mentally when someone asks for help with a bot. Unless your intentions really are malicious, in which case you should not share and just go figure it out yourself. Commented Jan 3, 2017 at 22:58
  • I am using site where I often comment stuff like thanks ect. It's simple @itsme86 site where I play a game or test stuff and I just after I am done write a comment. but due to a lot of comments like scrolling down, and writing a comment is time consuming. Its script I want to use only on my pc. I will use it on many links but same site. After commenting I will close site and go to another subsite. Nothing compitated more will be used. Commented Jan 3, 2017 at 23:15

1 Answer 1

0

You should use something like Selenium (http://www.seleniumhq.org/) which is a browser automation framework.

Selenium scripts can be written in many languages (including c#) and the scripts can be run on a variety of browsers. There is even browser plugins for creating scripts my recording a macro - no code required!

This is much more robust that using a browser control embedded in an app as that is only a cut down version of internet explorer I believe.

This is a rough sample of selenium in c#

    using OpenQA.Selenium;
    using OpenQA.Selenium.IE;
    using OpenQA.Selenium.Support.UI;

    var options = new InternetExplorerOptions();
    options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
    Driver = new InternetExplorerDriver(options);

    Driver.Navigate().GoToUrl("yourURL");

    Driver.FindElement(By.Id("User")).SendKeys("<your text>");
    Driver.FindElement(By.Id("but")).Click();
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.