WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

Switch to other Window WPF

Open dominik1776 opened this issue 9 years ago • 3 comments

We develop a WPF application and I have an obstacle when using the driver. During a test I swith to some other window (Login-->Dashboard panel) where other elements are located but the driver ,,see" only those from previous one.

Is impossible to find any element on the window using avaliable methods and also using:

	List<WebElement> elements = driver.findElements(By.xpath("//*"));
		
	for (WebElement el : elements){
			
		System.out.println(el.getText());

}

i am getting elements form previous window.

Have you got any idea how to handle this problem?

Thank you in advance for answer.

Best regards,

dominik1776 avatar Jul 17 '17 12:07 dominik1776

Better support for doing this is coming in v1.0 Today you would need to create a separate "root" session.

yodurr avatar Jul 17 '17 21:07 yodurr

Hi @dominik1776,

Not sure how you set up your test and test application. But the following test working well showing all the unique elements belonging to each specific windows:

foreach (var windowHandle in newlyOpenedEdgeWindows)
{
    session.SwitchTo().Window(windowHandle);
    Assert.AreEqual(session.CurrentWindowHandle, windowHandle);
    Assert.AreNotEqual(windowHandle, previousWindowHandle);
    previousWindowHandle = windowHandle;

    var elements = session.FindElementsByXPath("//*");
    foreach (WindowsElement el in elements)
    {
        System.Diagnostics.Debug.Print(el.Id);
    }

    EdgeBase.CloseEdge(session);
}

Can you please try it out? In the sample code, we can switch to different window and successfully find the right elements belonging the right window. The snippet above is taken from https://github.com/Microsoft/WinAppDriver/blob/v1.0-RC/Tests/WebDriverAPI/Window.cs#L154

timotiusmargo avatar Aug 16 '17 23:08 timotiusmargo

Hi Guys, Described issue still occurs. I gave a try to both mentioned solutions. The first one, when I create new instance of driver with root parameter works but there is a big deal of elements (I suppose that driver locate elements off all opened apps not just mine one). It takes a lot of time to locate elements.

Secound solution does not work I get error":"no such window", "message":"A request to switch to a window could not be satisfied because the window could not be found" and ,,Method not implemented" exception.

Env:

  • Selenium: org.seleniumhq.selenium selenium-api 3.8.1
  • Java Client: io.appium java-client 5.0.4
  • Appium io.appium java-client 5.0.4 Driver: v1.0 Release

My code sample: String newWindow = CalculatorSession.getWindowHandle(); CalculatorSession.switchTo().window(newWindow);

Driver console logs:

GET /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/window_handle HTTP/1.1 Accept-Encoding: gzip,deflate Cache-Control: no-cache Connection: Keep-Alive Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)

HTTP/1.1 200 OK Content-Length: 84 Content-Type: application/json

{"sessionId":"7AA21F12-79CC-4868-B45E-B65BC81D6C9B","status":0,"value":"0x00A40D52"}

========================================== POST /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/window HTTP/1.1 Accept-Encoding: gzip,deflate Connection: Keep-Alive Content-Length: 21 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)

{"name":"0x00A40D52"}

HTTP/1.1 400 Bad Request Content-Length: 154 Content-Type: application/json

{"status":23,"value":{"error":"no such window","message":"A request to switch to a window could not be satisfied because the window could not be found."}}

========================================== GET /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/window_handle HTTP/1.1 Accept-Encoding: gzip,deflate Cache-Control: no-cache Connection: Keep-Alive Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)

HTTP/1.1 200 OK Content-Length: 84 Content-Type: application/json

{"sessionId":"7AA21F12-79CC-4868-B45E-B65BC81D6C9B","status":0,"value":"0x00A40D52"}

========================================== GET /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/window_handles HTTP/1.1 Accept-Encoding: gzip,deflate Cache-Control: no-cache Connection: Keep-Alive Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)

HTTP/1.1 200 OK Content-Length: 86 Content-Type: application/json

{"sessionId":"7AA21F12-79CC-4868-B45E-B65BC81D6C9B","status":0,"value":["0x00340D7E"]}

========================================== POST /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/window HTTP/1.1 Accept-Encoding: gzip,deflate Connection: Keep-Alive Content-Length: 21 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)

{"name":"0x00340D7E"}

HTTP/1.1 200 OK Content-Length: 63 Content-Type: application/json

{"sessionId":"7AA21F12-79CC-4868-B45E-B65BC81D6C9B","status":0}

========================================== POST /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/execute HTTP/1.1 Accept-Encoding: gzip,deflate Connection: Keep-Alive Content-Length: 41 Content-Type: application/json; charset=utf-8 Host: 127.0.0.1:4723 User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)

{"script":"return window.name","args":[]}

HTTP/1.1 501 Not Implemented Content-Length: 84 Content-Type: text/plain; charset=utf-8

Command not implemented: POST: /session/7AA21F12-79CC-4868-B45E-B65BC81D6C9B/execute

Is there something to try in order to solve it?

dominik1776 avatar Jan 31 '18 15:01 dominik1776