microsoft / WinAppDriver

Windows Application Driver
MIT License
3.69k stars 1.4k forks source link

ComboBox item click in child dialog not working #1802

Open rmugione opened 2 years ago

rmugione commented 2 years ago

Hi The element within the ComboBox is found but the Click command does nothing. Replicated with the last version of WinAppDriver 1.2.2009.2003

using System;
using System.Windows.Forms;

namespace App
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
    }
    public class MainForm : Form
    {
        public MainForm()
        {
            var btn = new Button();
            SuspendLayout();

            btn.Name = "button1";
            btn.Text = "button1";
            btn.Click += (sender, e) => new Dlg().ShowDialog(this);

            ClientSize = new System.Drawing.Size(1264, 729);
            Controls.Add(btn);
            Name = "MainForm";
            Text = "MainForm";
            ResumeLayout(false);
        }
    }
    public class Dlg : Form
    {
        public Dlg()
        {
            var cmb = new ComboBox();
            SuspendLayout();

            cmb.DropDownStyle = ComboBoxStyle.DropDownList;
            cmb.Items.AddRange(new object[] { "Row 1", "Row 2", "Good row", "Row 3", "End"});
            cmb.Name = "cmb";
            cmb.Size = new System.Drawing.Size(352, 21);

            ClientSize = new System.Drawing.Size(424, 200);
            Controls.Add(cmb);
            Name = "Dlg";
            Text = "Dlg";
            ResumeLayout(false);
        }
    }
}
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;

namespace Test
{
    internal class Program
    {
        static void Main()
        {
            var capabilityValue = Path.GetFullPath(".\\App.exe");
            var appiumOptions = new AppiumOptions();
            appiumOptions.AddAdditionalCapability("app", capabilityValue);
            appiumOptions.AddAdditionalCapability("ms:waitForAppLaunch", "2");
            var homePage = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appiumOptions, TimeSpan.FromSeconds(60));

            homePage.FindElementByAccessibilityId("button1").Click();
            var dlg = homePage.FindElementByAccessibilityId("Dlg");

            var cmb = dlg.FindElementByAccessibilityId("cmb");
            cmb.Click();
            cmb.FindElementByName("Good row").Click();
        }
    }
}
anunay1 commented 2 years ago

What is shown in inspect? For windows form the combo box will be a seperate window?

rmugione commented 2 years ago

Hello nice to hear from you. The combo box is attached to a dialog, this dialog is opened by a mail window as a child. Note that combos in the main window work fine.

Inspect shows a List Item object. These forms are basic simple WinForm with common controls. The item is found and the Click method doesn't fail, simply does nothing.

image

Thanks

rmugione commented 2 years ago

Attach is the project used to replicate the issue AutomationSpike.zip

anunay1 commented 2 years ago

Your code is correct, also it finds the list item and clicks but the UI is not updated.

[WinAppDriver] {"sessionId":"1BBEB5AC-887F-4E14-8C05-86389FEB0C91","status":0,"value":{"ELEMENT":"42.1837940"}} [WD Proxy] Got response with status 200: {"sessionId":"1BBEB5AC-887F-4E14-8C05-86389FEB0C91","status":0,"value":{"ELEMENT":"42.1837940"}} [W3C (7866a42d)] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"42.1837940","ELEMENT":"42.1837940"} [HTTP] <-- POST /wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element 200 42 ms - 85 [HTTP] [HTTP] Request idempotency key: dc34f7fa-5180-4a2f-bd6b-377b66428cde [HTTP] --> POST /wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element/42.1837940/element [HTTP] {"using":"name","value":"Good row"} [W3C (7866a42d)] Calling AppiumDriver.findElementFromElement() with args: ["name","Good row","42.1837940","7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f"] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, accessibility id [WD Proxy] Matched '/element/42.1837940/element' to command name 'findElementFromElement' [WD Proxy] Proxying [POST /element/42.1837940/element] to [POST http://127.0.0.1:4725/wd/hub/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91/element/42.1837940/element] with body: {"using":"name","value":"Good row"} [WinAppDriver] ========================================== [WinAppDriver] POST /wd/hub/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91/element/42.1837940/element HTTP/1.1

[WinAppDriver] Accept: application/json, /

[WinAppDriver] Connection: keep-alive

[WinAppDriver] Content-Length: 35

[WinAppDriver] Content-Type: application/json; charset=utf-8

[WinAppDriver] Host: 127.0.0.1:4725

[WinAppDriver] User-Agent: appium [WinAppDriver] HTTP/1.1 200 OK

[WinAppDriver] Content-Length: 123

[WinAppDriver] Content-Type: application/json

[WinAppDriver]

[WinAppDriver] {"sessionId":"1BBEB5AC-887F-4E14-8C05-86389FEB0C91","status":0,"value":{"ELEMENT":"42.1837940.4.-2147483647.1837940.-4.3"}} [WD Proxy] Got response with status 200: {"sessionId":"1BBEB5AC-887F-4E14-8C05-86389FEB0C91","status":0,"value":{"ELEMENT":"42.1837940.4.-2147483647.1837940.-4.3"}} [W3C (7866a42d)] Responding to client with driver.findElementFromElement() result: {"element-6066-11e4-a52e-4f735466cecf":"42.1837940.4.-2147483647.1837940.-4.3","ELEMENT":"42.1837940.4.-2147483647.1837940.-4.3"} [HTTP] <-- POST /wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element/42.1837940/element 200 25 ms - 139 [HTTP] [HTTP] Request idempotency key: 2784f948-9fff-4f9a-80e7-e5a7992c56f3 [HTTP] --> POST /wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element/42.1837940.4.-2147483647.1837940.-4.3/click [HTTP] {} [W3C (7866a42d)] Driver proxy active, passing request on via HTTP proxy [WD Proxy] Matched '/wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element/42.1837940.4.-2147483647.1837940.-4.3/click' to command name 'click' [WD Proxy] Proxying [POST /wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element/42.1837940.4.-2147483647.1837940.-4.3/click] to [POST http://127.0.0.1:4725/wd/hub/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91/element/42.1837940.4.-2147483647.1837940.-4.3/click] with body: {} [WinAppDriver] ========================================== [WinAppDriver] POST /wd/hub/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91/element/42.1837940.4.-2147483647.1837940.-4.3/click HTTP/1.1

[WinAppDriver] Accept: application/json, /

[WinAppDriver] Connection: keep-alive

[WinAppDriver] Content-Length: 2

[WinAppDriver] Content-Type: application/json; charset=utf-8

[WinAppDriver] Host: 127.0.0.1:4725

[WinAppDriver] User-Agent: appium

[WinAppDriver]

[WinAppDriver] {} [WinAppDriver] HTTP/1.1 200 OK

[WinAppDriver] Content-Length: 63

[WinAppDriver] Content-Type: application/json

[WinAppDriver]

[WinAppDriver] {"sessionId":"1BBEB5AC-887F-4E14-8C05-86389FEB0C91","status":0} [WD Proxy] Got response with status 200: {"sessionId":"1BBEB5AC-887F-4E14-8C05-86389FEB0C91","status":0} [WD Proxy] Replacing sessionId 1BBEB5AC-887F-4E14-8C05-86389FEB0C91 with 7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f [HTTP] <-- POST /wd/hub/session/7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f/element/42.1837940.4.-2147483647.1837940.-4.3/click 200 331 ms - 65 [HTTP] [BaseDriver] Shutting down because we waited 60 seconds for a command [Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability' [Appium] Removing session '7866a42d-c2db-44e2-85ef-aa7d3cf3bf1f' from our master session list [WinAppDriver] Deleting WinAppDriver session [WinAppDriver] Deleting WinAppDriver server session [WD Proxy] Matched '/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91' to command name 'deleteSession' [WD Proxy] Proxying [DELETE /session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91] to [DELETE http://127.0.0.1:4725/wd/hub/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91] with no body [WinAppDriver] ========================================== [WinAppDriver] DELETE /wd/hub/session/1BBEB5AC-887F-4E14-8C05-86389FEB0C91 HTTP/1.1

[WinAppDriver] Accept: application/json, /

[WinAppDriver] Connection: keep-alive

[WinAppDriver] Content-Type: application/json; charset=utf-8

[WinAppDriver] Host: 127.0.0.1:4725

[WinAppDriver] User-Agent: appium [WinAppDriver] HTTP/1.1 200 OK

[WinAppDriver] Content-Length: 12

[WinAppDriver] Content-Type: application/json

[WinAppDriver]

[WinAppDriver] {"status":0} [WD Proxy] Got response with status 200: {"status":0} [WinAppDriver] WinAppDriver exited with code null, signal SIGTERM

rmugione commented 2 years ago

hello. Is there any news about this issue? Will be fixed soon? Thanks Ricardo

rmugione commented 2 years ago

For the comunity, this is the workarround

public void SelectItem(string text)
{
    homePage.FindElementByAccessibilityId("button1").Click();
    var dlg = homePage.FindElementByAccessibilityId("Dlg");

    var cmb = dlg.FindElementByAccessibilityId("cmb");
    cmb.Click();
    var listItemCount = cmb.FindElementsByTagName("ListItem").Count;
    for (int i = 0; i < listItemCount; i++) { cmb.SendKeys(Keys.Up); }          
    for (int i = 0; i < listItemCount; i++)
    {
        if (cmb.Text != text)
        {
            cmb.SendKeys(Keys.Down);
            continue;
        }
        cmb.SendKeys(Keys.Enter);
        return;
    }
}
Shakevg commented 2 years ago

@rmugione I had the same issue and fixing using Actions click:

public static IWebElement ClickUsingActions(this IWebElement element)
{
    var action = new Actions(element.GetDriver());
    action.MoveToElement(element).Click(element);
    action.Perform();
    return element;
}
rmugione commented 2 years ago

Hi @Shakevg thanks for the reply. I'm sorry but your solution doesn't work either. Please note that the app is a Windows form .Net 4.7.2 and test is .Net 6.0

This is certainly a WinAppDriver bug. I'think I'm not using the right channel to report it.

I've attached a spike app to replicate the bug. AutomationSpike.zip