Jump to content

AutoIt Script and Selenium upload file


 Share

Recommended Posts

Hi all,

I'm looking for solution my problem to upload the file by using Selenium and auto it script.

I would like to test, upload one file from my PC to my www page. I've

read that I can use AutoIT tool with Selenium to that. But I don't

know how can I use this AutoIt to create script and use it.

Can someone help me with this. please? I'm newbie with AutoIt.

For simple example:

1. I'm open http://tinypic.com/

2. Press button to upload the image (Browse)

3. Search image file from PC and upload the image

4. Press "Upload now" button on the page

Ad.1

I have simple selenium code to open the page:

namespace SeleniumProject.Blog

{

class AutoIt

{

private ISelenium selenium;

//public StringBuilder verificationerrors;

[setUp]

public void SetupTest()

{

selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://tinypic.com/");

selenium.Start();

selenium.WindowMaximize();

}

[Test]

public void AutoITtest(string filePath)

{

selenium.Open("/");

var procStartInfo = new System.Diagnostics.ProcessStartInfo(@"C:\Selenium\AutoIt\autotest.exe", "c:\\selenium\\pass.txt");

var proc = new System.Diagnostics.Process { StartInfo = procStartInfo };

proc.Start();

}

}

Ad.2 and Ad.3

My AutoIt code looks like:

autotest.au3 -> compile to autotest.exe

WinActivate("Browse");

Local $file = "c:\selenium\pass.png"

ControlSetText("Choose file", "", "Edit1", $file )

ControlClick("Choose file", "", "Open")

I know that isn't workin but I don't know how to change this to do this 4 steps.

Please help me!

Thanks a lot!!

Piotr

Link to comment
Share on other sites

Ok, my selenium code is run:

class AutoIt
    {
        private ISelenium selenium;
        //public StringBuilder verificationErrors;

        [SetUp]
        public void SetupTest()
        {
            selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://tinypic.com/");
            selenium.Start();
            selenium.WindowMaximize();

        }
     
        [Test]
        public void AutoITtest()
        
        {
            selenium.Open("/");
            System.Diagnostics.Process.Start("C:\\Selenium\\AutoIt\autotest.exe");
        }            
    }
}

But I don't know how to prepare Autoit script to upload image to the page http://tinypic.com. Please help me. I have something like this, but it doesn't work:

WinActivate("Browse");

Local $file = "c:\selenium\pass.txt"

ControlSetText("Choose file", "", "Edit1", $file )

ControlClick("Choose file", "", "Open")

I have following problem:

System.ComponentModel.Win32Exception : The system cannot find the file specified

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...