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.

test is failing selenium.common.exceptions.WebDriverException: Message: Failed to locate opened application window with appId:

See original GitHub issue

Hi all, I started having this problem when the driver fails to interact with the app actually its an RDP i am trying to automate the RDP file is opening successfully but not able to click or interact with the RDP like clicking on connect button doesnt work

below is the code

`import unittest from time import sleep

from appium import webdriver from appium.webdriver.extensions import session

class SimpleCalculatorTests(unittest.TestCase):

@classmethod
def setUpClass(self):
    # set up appium
    desired_caps = {}
    desired_caps["app"] = r"C:\jtracker\jailtracker.rdp"
    self.driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4723',
        desired_capabilities=desired_caps)

@classmethod
def tearDownClass(self):
    self.driver.quit()



def test_addition(self):
   self.driver.find_element_by_xpath("/Button[@ClassName=\"Button\"][@Name=\"Connect\"]").click()

    sleep(5)

if name == ‘main’: suite = unittest.TestLoader().loadTestsFromTestCase(SimpleCalculatorTests) unittest.TextTestRunner(verbosity=2).run(suite)

`

below is the error i m getting i console

Failure Traceback (most recent call last): File “C:\Program Files\Python374\lib\unittest\suite.py”, line 163, in _handleClassSetUp setUpClass() File “C:\Users\VellaSR\PycharmProjects\JTracker\launchJtracker.py”, line 17, in setUpClass desired_capabilities=desired_caps) File “C:\Users\VellaSR\PycharmProjects\JTracker\venv\lib\site-packages\appium\webdriver\webdriver.py”, line 156, in init AppiumConnection(command_executor, keep_alive=keep_alive), desired_capabilities, browser_profile, proxy File “C:\Users\VellaSR\PycharmProjects\JTracker\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 157, in init self.start_session(capabilities, browser_profile) File “C:\Users\VellaSR\PycharmProjects\JTracker\venv\lib\site-packages\appium\webdriver\webdriver.py”, line 225, in start_session response = self.execute(RemoteCommand.NEW_SESSION, parameters) File “C:\Users\VellaSR\PycharmProjects\JTracker\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 321, in execute self.error_handler.check_response(response) File “C:\Users\VellaSR\PycharmProjects\JTracker\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Failed to locate opened application window with appId: C:\jtracker\jailtracker.rdp, and processId: 3488

C:\Program Files\Python374\lib\unittest\suite.py:170: ResourceWarning: unclosed <socket.socket fd=580, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=(‘127.0.0.1’, 59865), raddr=(‘127.0.0.1’, 4723)> self._addClassOrModuleLevelException(result, e, errorName) ResourceWarning: Enable tracemalloc to get the object allocation traceback

Ran 0 tests in 3.503s

FAILED (errors=1)

Process finished with exit code 1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
shoaibmansoorcommented, May 12, 2021

Hi @nabilalakhani It looks, you are using desktop session directly to control the application. yes, it is slow with xpath or other types of identifiers as well.

I would suggest using desktop session for taking access to the application only, not to control the application. Use this feature to control already opened application through the desktop session. It will not be slow with xpath or any other element identifier.

Try to use this code to get access to the application

desktop_session = self.driver
element  = desktop_session.find_elements_by_xpath('XPATH_TO_SELECT_APPLICATION_HANDLE')
handle = element.get_attribute('NativeWindowHandle')
top_level_window_handle = str(hex(int(handle)))

new_desired_caps = {}
new_desired_caps['appTopLevelWindow'] = top_level_window_handle
new_desired_caps['deviceName] = 'WindowsPC'
new_desired_caps['platformName] = 'Windows'
new_desired_caps['newCommandTimeout] = 3000
self.driver = webdriver.Remote(command_executor='http://127.0.0.1:4723', desired_capabilities=new_desired_caps)

# Test code goes here
0reactions
anunay1commented, May 12, 2021

There is a known issue with slowness with xpath, better use some other method to locate elements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenQA.Selenium.WebDriverException : Failed to locate ...
taskschd test issue: OpenQA.Selenium.WebDriverException : Failed to locate opened application window with appId: C:\\WINDOWS\\System32\\taskschd ...
Read more >
Code is not able to locate my application - Support
I am writing my first code for appium.I am trying to open calculator by passing location to desirable capabilities.
Read more >
UI testing for Windows apps with WinAppDriver and Appium
The full application must be up & running, while unit testing ... WebDriverException: Failed to locate opened application window with appId: ...
Read more >
Windows Desktop Application Test Automation with ...
Windows Application Driver (WinAppDriver) is a service supporting Selenium-like UI Test Automation on Windows Applications.
Read more >
What application types are supported by winappdriver
Winappdriver can start executables (generally .exe files on Windows). I suspect your .msc file is a management saved console?
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