2

I am a newbie in web browser automation, and I choose Google pages as the samples to learn.

I try to simulate a file upload to Google Drive, but I encounter several problems.

http://s4.postimage.org/jbx6c3q3h/Untitled_1.jpg

private void webBrowser_DocumentCompleted ( object sender, WebBrowserDocumentCompletedEventArgs e ) {
    HtmlElement element = webBrowser.Document.GetElementById( "contentcreationpane" );
    if ( element != null )
        UploadFile();
}


private void UploadFile () {
    HtmlElementCollection elements = webBrowser.Document.GetElementsByTagName( "div" );
    foreach ( HtmlElement element in elements ) {
        if ( element.GetAttribute( "data-tooltip" ) == "Upload" ) {
            element.InvokeMember( "click" );
            break;
        }
    }

    HtmlElement uploadButton = webBrowser.Document.GetElementById( ":1" );
    if ( uploadButton != null ) {
        uploadButton.InvokeMember( "click" );
    } else {
        Exception goes here! Is it necessary to do a wait after previous element "Upload" is clicked?
    }
}
1
  • Yes. You have to purposefully wait until the page is completely loaded. Commented Feb 16, 2017 at 9:19

3 Answers 3

1

You can try to use some kind of web UI testing framework, like Selenium. It can help you record the test case and can even generate C# code to paste in your test project.

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

1 Comment

I did tried this one. However, it doesn't work too. It cannot record the click event on "Upload" button of Google Drive.
1

This may be intentionally hard to automate - I know GMail (and Yahoo and other webmail providers) purposefully make it complicated to automate sending email via their web interfaces.

So uploading documents to Google Drive may be similar; it's likely that to prevent abuse, Google has put roadblocks in place to make it difficult to automate uploads.

Comments

1

You can use a mixture of Selenium and Sikuli. Selenium is really a great tool for browser automation. However in case you have to use UI elements which are not automatable by Selenium, I would recommend to use Sikuli for C#. Here I have found an example how it could look like:

    Launch.Start();  
    IwebDriver driver = new ChromeDriver("D:/>SeleniumDrivers/ChromeDriver32");  
    driver.Manage().Window.Maximize();  
    driver.Navigate.GoToURL("http://www.csharpcorner.com/");  
    Screen scr = new Screen();  
    scr.Click(Image1, true);  
    scr.wait(10);  
    scr.Type(Image2, "string to Enter", KeyModifier.None);  
    scr.wait(10);  
    scr.Type(Image3, "string to enter", keyModifier.None);  
    scr.wait(10);  
    scr.Type(Image4, "string to enter", KeyModifier.None);  
    scr.wait(10);  
    scr.Type(Image5, "string to enter", KeyModifier.None);  
    scr.wait(10);  
    driver.quit();  

You can easily interact with UI elements and simulate keyboard input with Sikuli.

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.