microsoft / WinAppDriver

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

Winappdriver couldn't find element by name #1178

Open fabianavilela1908 opened 4 years ago

fabianavilela1908 commented 4 years ago

Hi, I'm a beginner in automation and I'm trying to automating a desktop application test using C# with WinAppDriver, but the tool cannot find the elements. The element name is correct. I can't search for another locator because there isn't.

I'm trying to click on the file menu (it worked) and in sequence on the element "Importar script" but this second element is not identified by winappdriver.

print

The error message is as follows: org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

Here is my code. Can anybody help me, please?

 // 1 - Open Viewer 
                    WindowsDriver<WindowsElement> leafSession;
                    AppiumOptions desiredCapabilities = new AppiumOptions();
                    desiredCapabilities.AddAdditionalCapability("app", @"C:\Program Files (x86)\Viewer.lnk");

                    leafSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredCapabilities);
                    leafSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(8);
                    WindowsElement menuArchive = leafSession.FindElementByName("Arquivo Alt+A");
                    Assert.IsTrue(menuArchive.Displayed);
                    menuArchive.click();  **// until here it works** 

                if (leafSession.CurrentWindowHandle != leafSession.WindowHandles.Last())
                    {

                    leafSession.SwitchTo().Window(leafSession.WindowHandles.Last());
                    WindowsElement importar = leafSession.findElementByName("Importar Script... Ctrl+Shift+I");
                    Assert.IsTrue(importar.Displayed);
                    importar.click();

                    }
VijayHugar commented 4 years ago

Did you go through sample and Test projects of winappdriver before you started with your project ? If not, please go through it. This will save lot of your time while fixing issues if any https://github.com/microsoft/WinAppDriver/tree/master/Tests or https://github.com/microsoft/WinAppDriver/tree/master/Samples

Also, about your question -Where is your test failing ? what error are you getting ?

fabianavilela1908 commented 4 years ago

Hi, @VijayHugar,

Thanks for the reply and sorry for the delay. I had given up on Winappdriver but I resumed my search for a solution to my problem. For some reason I am still unable to identify the element by name. I've tried some solutions like identifying the element using xpath or using WindowsHandles, but it didn't work

I changed the description of my problem, if you can analyze it, I will be grateful.

anunay1 commented 4 years ago

What does inspect show, can you share