in my test web page I have to upload a file, the uploader is flash based. I used AutoIT to upload the file but my problem is im unable to click that add button so that the upload dialogue box display and autoIT can do its job ..

driver.findElement(By.xpath("html/body/div[3]/div[2]/div/div/table/tbody/tr[2]/td/div/form/div/div[6]/div[1]/div[2]/object")).click();

the error im getting is element not found error.. can u guys plz help me how to click that flash button. i have even used Firepath, Css and i dont know what to do. Plz Help

Thank you

有帮助吗?

解决方案 2

You cannot automate flash objects using Selenium, it is way out of the scope of what Selenium can do.

You need to edit the AutoIT script to click the Add button for you, Selenium will not be able to do this for you.

其他提示

While this answer is not related to Selenium I think it might help somebody else looking for an answer to this problem.

I've been in this situation before and while is not possible to use Selenium to "click" on a flash button there is something less than stellar to click on that button and keep going with what you need to do.

Any flash movie on a web page is like any other window, just not so accessible as any other element but if you go "low" enough you can enumerate the windows that belong to that browser instance and find the flash window.

So the idea is as follows:

  1. Find the active browser instance (IE, FF, Chrome, etc. in this case IE)

    var ps = Process.GetProcessesByName("iexplore").Select(p => p.Id);
    foreach (var handle in ps.SelectMany(EnumerateProcessWindowHandles))
    {
        GetChildWindows(handle);
        if (_macromediaFound != false){break;}
    }
    
  2. List all it's child windows (EnumerateWindowsEx using Windows API)

    public static List<IntPtr> GetChildWindows(IntPtr parent)
    {
       List<IntPtr> result = new List<IntPtr>();
       GCHandle listHandle = GCHandle.Alloc(result);
       try
       {
           EnumWindowProc childProc = new EnumWindowProc(EnumWindow);
           EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));
       }
       finally
       {
           if (listHandle.IsAllocated)
           listHandle.Free();
       }
       return result;
    }
    
  3. Find the window that has the Window with a ClassName called MacromediaFlashPlayerActiveX (this is in IE)

The previous code will call the function (method) EnumWindow every time it finds a child window on each of the processes liste on step 1

    private static bool EnumWindow(IntPtr handle, IntPtr pointer)
    {
        StringBuilder message = new StringBuilder(1000);
        SendMessage(handle, WmGettext, message.Capacity, message);
        StringBuilder classN = new StringBuilder(1000);
        GetClassName(handle, classN, classN.Capacity);
        if (classN.ToString().Contains("MacromediaFlashPlayerActiveX"))
        { // continues below....
  1. With that information you'll have the XY position of the window and you'll need to find the right XY to click the button on the screen.

        Thread.Sleep(2000); // this will allow any needed time to actually draw the flash on screen
        Rectangle rect = new Rectangle();
        GetWindowRect(handle, ref rect);
        var oldPos = Cursor.Position;
        Point clientPoint = new Point(rect.X + 20, rect.Y + 10); // In this particular Flash Movie the Upload File button is 20 points from x and 10 points from Y)
        if (rect.X != 0 && rect.Y != 0)
        {
            Cursor.Position = new Point(clientPoint.X, clientPoint.Y);
        }
    
  2. Send a click event to those coordinates

        mouse_event(MouseEventfLeftdown, 0, 0, 0, UIntPtr.Zero);
        mouse_event(MouseEventfLeftup, 0, 0, 0, UIntPtr.Zero);
        Thread.Sleep(2000);
        // Options but "clean" return the mouse to it's original position
        Cursor.Position = oldPos;
    
  3. Once the click has been sent look for a window of ClassName #32770 (at least with IE)

    hwndTmp = (IntPtr)FindWindow("#32770", "Text of the upload window");
    

From here on it should be pretty straightforward to continue with the process.

I know that this is not the cleanest solution (you need a logged in user and also have a screen to get the coordinates from) but I know for a fact that there are situations were there is no alternative for this and you need to find a solution for it.

Hope this helps.

It can be done using FlashSelenium

https://code.google.com/p/flash-selenium/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top