question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find element in WindowsForm

See original GitHub issue

When the existing form Hide() and a new form Show(), cannot find the element in new form. When I trying to get the title from session after the new form shown, the result is still the title of old form. How can I find the element in new form?

Thx.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
naeemakramcommented, Mar 12, 2019

Try finding the new form first inside the old session, once you have the WinElement containing the new form you should be able to find things on the second form. Please let me know if it worked.

0reactions
naeemakramcommented, Mar 15, 2019

Thanks very much for sharing the code.

On Fri, Mar 15, 2019 at 9:23 AM daleqq notifications@github.com wrote:

The code is based on Java, here is the code for your reference:

public class WindowsFormApplicationTest {

private static WindowsDriver ApplicationSession = null;
private static WindowsDriver rootSession = null;
private static WindowsDriver mainwindowSession = null;

@BeforeClass
public static void setup() {
    try {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("app", "WinFormApplication.exe");
        capabilities.setCapability("appWorkingDir", "XXXXX\\Debug");
        ApplicationSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);
        ApplicationSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

        DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
        desktopCapabilities.setCapability("app", "Root");
        rootSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), desktopCapabilities);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
    }
}

@Test
public void testApplicationStarted() throws Exception {
    System.out.println("Title: " + ApplicationSession.getTitle() + " with Handle: " + ApplicationSession.getWindowHandle());
    ApplicationSession.findElementByAccessibilityId("username").sendKeys("hello");
    ApplicationSession.findElementByAccessibilityId("password").sendKeys("hello");
    ApplicationSession.findElementByAccessibilityId("button1").click();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
    }

    WebElement main = rootSession.findElementByAccessibilityId("Main");
    String handle = main.getAttribute("NativeWindowHandle");
    String hexHandle = Integer.toHexString(Integer.parseInt(handle));

    DesiredCapabilities mainWindowCapabilities = new DesiredCapabilities();
    mainWindowCapabilities.setCapability("appTopLevelWindow", hexHandle);

    mainwindowSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), mainWindowCapabilities);


    mainwindowSession.findElementByAccessibilityId("textBox14").sendKeys("421");
    mainwindowSession.findElementByAccessibilityId("Search").click();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
    }
}

@Before
public void Clear() {
}

@AfterClass
public static void TearDown() {
    if (mainwindowSession != null) {
        mainwindowSession.quit();
    }
    mainwindowSession = null;

    if (ApplicationSession != null) {
        ApplicationSession.quit();
    }
    ApplicationSession = null;

    if (rootSession != null) {
        rootSession.quit();
    }
    rootSession = null;
}

}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/WinAppDriver/issues/617#issuecomment-473154119, or mute the thread https://github.com/notifications/unsubscribe-auth/AGkP-RUOFlAwvdoVUhr02rM51DfEsu4Hks5vWyBdgaJpZM4bV7J5 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# white, can't find element at window
I am trying to automate WinForm application, very basic. Manual steps for automation: Open window. Download file to this window. Find caption at ......
Read more >
UI automation action fails with "Failed to get UI element" or ...
Cause 3: Application's window name or element's underlying structure has changed. Either the window name of the application or the underlying ...
Read more >
Can't find Element on other machine in Citrix - Studio
The robot needs to navigate in the top bar, the same as in Windows Explorer. I run in to the problem that the...
Read more >
UI elements cannot be identified correctly (Windows Form)
Hello, I have some problems with UI identification. I use Ranorex (9.4.1) to test an Application, which is programed with Windows Form.
Read more >
FindElement And FindElements Commands in C#
Locating elements in WebDriver is done by using the FindElement(By.Locator()) method. The FindElement methods take a locator or query object ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found