3

When I try to run any kind of code using winium, it will open the app, but then won't execute any of the code afterwards. It's not as if it throws up an error, it just hangs there and won't move on.

I Am using Python 3.7 on a Windows 10 PC.


I have tried the two 'magic' examples that are listed on the github wiki page for Winium, but even that doesn't work. I am able to use selenium to do automated web testing, so I don't think the selenium module is the issue. I have tried importing the time module and making it sleep for 10 seconds in between lines but this has no effect on the outcome.


from selenium import webdriver

driver = webdriver.Remote(
    command_executor='http://localhost:9999',
    desired_capabilities={
        "debugConnectToRunningApp": 'false',
        "app": r"C:/windows/system32/calc.exe"
    })

# THIS IS WHERE IT SEEMS TO PAUSE INDEFINITELY

window = driver.find_element_by_class_name('CalcFrame')
view_menu_item = window.find_element_by_id('MenuBar').find_element_by_name('View')

view_menu_item.click()
view_menu_item.find_element_by_name('Scientific').click()

view_menu_item.click()
view_menu_item.find_element_by_name('History').click()

window.find_element_by_id('132').click()
window.find_element_by_id('93').click()
window.find_element_by_id('134').click()
window.find_element_by_id('97').click()
window.find_element_by_id('138').click()
window.find_element_by_id('121').click()

driver.close()

I would expect it to press the corresponding buttons, but it doesn't seem to do anything except open the calculator app.

birdistheword99
  • 179
  • 1
  • 15

2 Answers2

1

I think this example is written for an older version of calculator. In Windows 10, the "Scientific" button is under the Menu button.

Menu Button Scientific

You'll have to find the menu button, click it, and then look for the element "Scientific" in the list.

Also, the numeric values for your arithmatic case are not correct. Pick up a UI inspector tool (inspect.exe, uispy, etc...) to make sure you are targeting the elements correctly.

jlewkovich
  • 2,725
  • 2
  • 35
  • 49
Chris R.
  • 11
  • 1
  • Thanks for the heads up, you're right the application had changed and so the Id's and names it uses to identify elements needed changing, but it still doesn't work, it gets as far as opening the program and then stops. – birdistheword99 Jan 31 '20 at 15:27
0

Winium does not supports latest version of selenium,

for me selenium==3.141.0 + python 3.11 working fine in windows 11.

make sure to check the windows display resolution is 100%, otherwise winium will not work.

here is a working code for calculator for pressing 1 to 9 buttons by their id.

import time, os
from selenium.webdriver import Remote

# Start server 
os.startfile("winium.exe")

# Set desired capabilities for Winium driver
capabilities = {
        "debugConnectToRunningApp": 'false',
        "app": r"C:\Windows\System32\calc.exe", }

# Start Winium driver
driver = Remote(command_executor='http://localhost:9999', desired_capabilities=capabilities)

# Find the Notepad window and send keys
time.sleep(5)
print("Sleep Over")
try:
    for i in range(10):
        driver.find_element_by_id(f"num{i}Button").click()
    print("Writing...successful")
except Exception as e:
    print(f"Exception : {e}")

# kill the server 
os.system("TASKKILL /F /IM winium.exe")

make sure only one winuim instance is running // kill all instance from task manager.

to make sure you can check the port 9999 state.

netstat -a -o -n | findstr 9999