Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3845262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:13:02+00:00 2026-05-19T16:13:02+00:00

I am using Watin to copy a image to the clipboard, I am getting

  • 0

I am using Watin to copy a image to the clipboard, I am getting this error when I do so,

is there a work around to this using AlertDialogHandler?

 public System.Drawing.Image GetPicture(WatiN.Core.Image image, ref IE browser)
        {
            if (image == null || !image.Exists || string.IsNullOrEmpty(image.Src))
                return null;
            const string t_js =
                    @"var div = document.images[{0}];
                      div.contentEditable ='true';
                      var controlRange;
                      if(document.body.createControlRange)
                      {{
                           controlRange = document.body.createControlRange();
                           controlRange.addElement(div);
                           controlRange.execCommand('Copy');
                       }}
                       div.contentEditable = 'false';";

            var cnt = -1;
            foreach (var image1 in browser.Images)
            {
                cnt++;
                if (image1 != null && image1.Exists && !string.IsNullOrEmpty(image1.Src) && image1.Src.ToLower() == image.Src.ToLower())
                    break;
            }
            var script = string.Format(t_js, cnt);


            WatiN.Core.DialogHandlers.AlertDialogHandler alertDialogHandler = new WatiN.Core.DialogHandlers.AlertDialogHandler ();
            using (new WatiN.Core.DialogHandlers.UseDialogOnce(browser.DialogWatcher, alertDialogHandler ))
            {

                browser.RunScript(script); // Exception comes here !!


alertDialogHandler.WaitUntilExists();

                alertDialogHandler.OKButton.Click();

                browser.WaitForComplete();

            }



            var data = Clipboard.GetDataObject();
            if (data == null)
                return null;
            var q = data.GetFormats();
            q.ToString();
            var q2 = data.GetFormats(true);
            q2.ToString();
            if (data.GetDataPresent(DataFormats.Bitmap))
            {
                var img = data.GetData(DataFormats.Bitmap, true);
                return img as System.Drawing.Image;
            }
            if (data.GetDataPresent(DataFormats.Dib))
            {
                var img = data.GetData(DataFormats.Dib, true);
                return img as System.Drawing.Image;
            }
            if (data.GetDataPresent(DataFormats.EnhancedMetafile))
            {
                var img = data.GetData(DataFormats.EnhancedMetafile, true);
                return img as System.Drawing.Image;
            }
            if (data.GetDataPresent(DataFormats.MetafilePict))
            {
                var img = data.GetData(DataFormats.MetafilePict, true);
                return img as System.Drawing.Image;
            }
            if (data.GetDataPresent(DataFormats.Tiff))
            {
                var img = data.GetData(DataFormats.Tiff, true);
                return img as System.Drawing.Image;
            }
            if (data.GetDataPresent(DataFormats.Serializable))
            {
                var img = data.GetData(DataFormats.Serializable, true);
                return img as System.Drawing.Image;
            }
            return null;
        }

Thanks!

image of the security exception:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:13:02+00:00Added an answer on May 19, 2026 at 4:13 pm

    I believe it has to do something with IE Security settings

    Goto
    Security Tab -> Select proper zone (Internet/Local/etc) -> Click on Custome Level button -> Enable (Scripting – > Allow programmatic clipboard access)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WatiN for web application testing. There is a field called enter choices
I'm using Watin in C# console app to crawl websites, there are five console
I am currently using WatiN to automate a proprietary website at my work, and
I'm trying to get the following code to work using both Watin and HttpWatch.
Is there any way of changing the timeout for Firefox using WatiN? It throws
I am using WatiN 2.0.20.0 with IE 8.0.7 . While using I am getting
Is there a way to verify is element hidden or not - using watin.
How do I upload a file using WatiN? Is it possible for this file
I am using WatiN and trying to scrape an image URL from a weblink,
When I am writing this piece of code it works fine using System; using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.