2gis / Winium.Desktop

Winium.Desktop is Selenium Remote WebDriver implementation for automated testing of Windows application based on WinFroms and WPF platforms.
Mozilla Public License 2.0
401 stars 141 forks source link

SwitchtoWindow using winium.desktop #156

Open nageshb2020 opened 7 years ago

nageshb2020 commented 7 years ago

Automating my windows application. Clicking on one button a new Window opens(child window) i am not able to click on any element on the new window. If we try to click "driver.findElementByname("ABC").click" its shows NoSuchElementException. "driver.switchto.Window()" is also not working. please help

muruga85 commented 7 years ago

@sn2691 --> Identify the child window using Classname/AutomationID and then try inspecting that element in childwindow.

Sample below:

IWebElement ChildWindow = winiumdriver.FindElementByClassName("XXX"); IWebElement Element1 = ChildWindow.FindElementByName("ABC"); Element1.Click();

Please let me know if this works.

nits-PT commented 6 years ago

Is that working for you ? I am trying to access a new window which opens up on clicking a button for a MS Word plugin. it's actually dialog box. I am able to access each element for that window except some elements which comes after passing through many ancestors.

Children: Container has no children Ancestors: "Adjacent citation found and merged." : outline : focused,focusable "Adjacent citation found and merged." : window : focused,focusable "Adjacent citation found and merged." : client : focusable "Adjacent citation found and merged." : window : focusable "Insert/Edit Citation" : client : focusable "Insert/Edit Citation" : window : moveable,focusable "Desktop 1" : client : focusable "Desktop 1" : window : focusable

Identification ClassName: "" ControlType: "ControlType.TreeItem" Culture: "(null)" AutomationId: "" LocalizedControlType: "tree item" Name: "haa" ProcessId: "5272 (WINWORD)" RuntimeId: "1 199220 600 1952433584" IsPassword: "False" IsControlElement: "True" IsContentElement: "True"

Issue is I am not able to access the element through name. I am used this in my code.

WebElement box = driver.findElement(By.id("WEditCitation")); WebElement editCitationBox = box.findElement(By.id("pnlMain")); WebElement tree = editCitationBox.findElement(By.name("Adjacent citation found and merged."));

    WebElement HAA = tree.findElement(By.xpath("//*[@name='haa' and @ControlType='ControlType.TreeItem']"));
    HAA.click();
Shashank9190 commented 6 years ago

For my current project i am using selenium with winium. It is a web cum windows application. So the issue is, after clicking on a button on a web page, 'Save as' dialog is appearing. I wanted to perform the operation in Save as window. How will i do it, If the dialog window is already open. I have already used the below one: DesktopOptions option = new DesktopOptions { DebugConnectToRunningApp = true, ApplicationPath = @""}; Here i do not have the path to for dialog box. Please help me out of this and suggest the proper solution.

Gaurank-Verma commented 6 years ago

Hi, Winium driver is unable to locate the element on a desktop application. Even though, its automation id present and same have been provided in the code to find the respective element. Every time, I'm getting an exception "Element cannot be found".

**Related Image: query

Winium driver is able to locate login id & pwd label but it's could not locate corresponding TextBoxes. The UI of my desktop application is attached as image. Plz help me.

Avinash9969 commented 6 years ago

@Gaurank-Verma Can you please post the code you used to access the textbox?

Gaurank-Verma commented 6 years ago

Hi @Avinash9969,

Please find my code snippet -

package testCases; import java.net.MalformedURLException; import java.net.URL;

import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.winium.DesktopOptions; import org.openqa.selenium.winium.WiniumDriver;

public class LoginPage {

public static void main(String[] args) throws MalformedURLException, InterruptedException {
    DesktopOptions option = new DesktopOptions();
    option.setApplicationPath("C:\\Program Files (x86)\\abcd\\abcd\\abcd.exe");
    Thread.sleep(2000);
    WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option);
    Thread.sleep(2000);

    //User Id Label
    driver.findElementByName("User Id    :");
    System.out.println("User ID element found"); 

    //Password Label
    driver.findElementByName("Password  :");
    System.out.println("Password element found"); 

    //User Id Text box
    driver.findElementById("textBoxLoginId").sendKeys("abcd");
    System.out.println("textBoxLoginId element found"); 
    Thread.sleep(2000);

    //Password Text box
    driver.findElementById("textBoxLoginPassword").sendKeys("abcd");
    System.out.println("textBoxLoginPassword element found"); 
    Thread.sleep(2000);

    //Login Button
    driver.findElementById("btnLogin").click();
    System.out.println("Login button clicked"); 
    Thread.sleep(2000);

    //Closing driver
    driver.close();
}

}

Please let me know if I'm making an error while accessing the Textboxes. Thanks in advance.

Hebertgj86 commented 6 years ago

@Gaurank-Verma Can you please post the solution?, i have the same problem

amod-thakur commented 6 years ago

Hi,

It appears that the driver object is not pointing to the login section. You can try to pass the control to the login section by switching to the section first.Try the following:

WebElement login_screen = driver.findElementByName(name of the login section);

String loginWin =Login_screen.getAtrribute("windowHandle");

driver.window().switch to(loginWin);

//Code to interact with the wlemts on login section.

murariagrawal commented 6 years ago

@Chintzz
Following are the code import java.net.MalformedURLException;

import java.net.URL;

import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.winium.DesktopOptions;

import org.openqa.selenium.winium.WiniumDriver;

public class Test1 {

public static void main(String[] args) throws MalformedURLException, InterruptedException {

DesktopOptions option = new DesktopOptions();

option.setApplicationPath("C:\Windows\System32\calc.exe");

WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option);

Thread.sleep(5000);

driver.findElement(By.name("Seven")).click();

driver.findElement(By.name("Plus")).click();

driver.findElement(By.name("Eight")).click();

driver.findElement(By.name("Equals")).click();

Thread.sleep(5000);

String output = driver.findElement(By.id("CalculatorResults")).getAttribute("Name");

System.out.println("Result after addition is: "+output);

WebElement newWindow = driver.findElement(By.name("calc.exe Properties")); String newWindowHandle = newWindow.getAttribute("windowHandle"); driver.switchTo().window(newWindowHandle);

driver.findElement(By.name("Close")).click();

driver.quit();

}

anything wrong I have done since its not working for me

muhammadabdullah084 commented 5 years ago

@Gaurank-Verma I did the same but I got Error

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Element cannot be found (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 10.69 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06' System info: host: 'abdullah', ip: '192.168.1.126', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_51' Driver info: org.openqa.selenium.winium.WiniumDriver Capabilities [{app=C:\HC-Finance\HoneycombERP-BE.exe, args=, innerPort=9998, debugConnectToRunningApp=false, keyboardSimulator=1, launchDelay=0, platform=ANY}] Session ID: AwesomeSession *** Element info: {Using=name, value=txtUser} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:353) at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:451) at org.openqa.selenium.By$ByName.findElement(By.java:303) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:345) at testCase.Myfirstdemo.main(Myfirstdemo.java:26)