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.

findElementByName is not working ?

See original GitHub issue

I am trying to automate an application using Java. Following are my configuration details,

Appium

<dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>5.0.4</version> </dependency>

Driver version: v1.0

Code:

DesiredCapabilities capability = new DesiredCapabilities(); capability.setCapability("app", "C:\\Users\\<current user>\\Desktop\\App.lnk"); capability.setPlatform(Platform.WIN10); try { driver = new WindowsDriver<WindowsElement>(new URL("http://127.0.0.1:4723"), capability); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); Thread.sleep(5000); } catch (MalformedURLException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } WindowsElement element = driver.findElementByName("Folder Compare"); element.click();

Exception:

Exception in thread “main” org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: ‘3.6.0’, revision: ‘6fbf3ec767’, time: ‘2017-09-27T15:28:36.4Z’ System info: host: ‘PC252611’, ip: ‘10.219.211.41’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_121’ Driver info: io.appium.java_client.windows.WindowsDriver Capabilities [{app=C:\Users\589103\Desktop\Beyond Compare 4.lnk, javascriptEnabled=true, platformName=WINDOWS, platform=WINDOWS}] Session ID: 4B584146-AAB2-4875-A29A-A5C68A676C3B *** Element info: {Using=name, value=Folder Compare} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166) at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82) at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:356) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.findElement(WindowsDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:434) at io.appium.java_client.DefaultGenericMobileDriver.findElementByName(DefaultGenericMobileDriver.java:110) at io.appium.java_client.AppiumDriver.findElementByName(AppiumDriver.java:1) at io.appium.java_client.windows.WindowsDriver.findElementByName(WindowsDriver.java:1) at WinApp.main(WinApp.java:32)

Used inspect.exe to spy an object and tried to click the button named “Folder Component”

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
timotiusmargocommented, Mar 21, 2018

Hi @kumarkrish85,

Beyond Compare 4 application opens a temporary application window with Tapplication ClassName on application startup. Windows Application Driver treats this temporary window as the main application window for the created session. This window will eventually disappears when the actual main application window containing the Folder Compare button appears. But at this point, your WinAppDriver session is still pointing to the temporary window and as a result you will not be able to locate the button.

To overcome this scenario, you can simply switch the created session to the main application window as soon as it appears. For example:

DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Beyond Compare 4.lnk");
session = new WindowsDriver<WindowsElement>(new Uri(CommonTestSettings.WindowsApplicationDriverUrl), appCapabilities);
Assert.IsNotNull(session);

// Wait until the main application window appears. This can also be replaced by a simple sleep
var windowHandles = session.WindowHandles;
for (int attempt = 0; attempt < 5 && windowHandles.Count > 1; attempt++)
{
    Thread.Sleep(TimeSpan.FromSeconds(1));
    windowHandles = session.WindowHandles;
}

// Switch session to the only application top level window that is still active (an indication that this is the main window)
if (windowHandles.Count >= 0)
{
    session.SwitchTo().Window(windowHandles[0]);
}

Assert.AreEqual(@"Home - Beyond Compare", session.Title);
WindowsElement folderCompareButton = session.FindElementByName("Folder Compare");
folderCompareButton.Click();
0reactions
hassanuzcommented, Jun 5, 2018

Hi @Kranthi9704,

Can you please open a new issue with additional logs (from WinAppDriver.exe console)?

Closing this ticket as original issue seems to be resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium find element by name not working
Selenium find element by name not working ... I am trying to automate ExtJs application. The field ID changes when ever there is...
Read more >
findElementsByAccessibilityId and findElementByName not ...
I am doing hybrid app iOS automation using Appium. Not able to find the element using findElementsByAccessibilityId and findElementByName.
Read more >
PopupBaseEdit function of LayoutHelper. ...
PopupBaseEdit function of LayoutHelper.FindElementByName do not work. ... I want to create a custom control inherited from PopupBaseEdit.When I ...
Read more >
FindElementByName method of IUMLHelper makes RSA ...
Problem summary. Whenever there are matching elements whose immediate container is not the element at which the search begins, the implementation of the ......
Read more >
Finding web elements
One solution is to locate an element with a unique attribute that is an ancestor of the desired element and not an ancestor...
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