Winium/selenium running calc

#3
by IgorMarnat - opened

πŸ˜ƒ: Write a code starting calculator app in windows and calculating square of five using selenium and python
πŸ€–: Here is an example of how you could write a code starting calculator app in Windows using Selenium and Python:

from selenium import webdriver

# Create a new instance of the Firefox webdriver
driver = webdriver.Firefox()

# Navigate to the calculator app
driver.get("https://www.calculator.net/")

# Enter the number to square
driver.find_element_by_name("number").send_keys("5")

# Click the square button
driver.find_element_by_name("square").click()

# Get the result
result = driver.find_element_by_name("result").text

# Print the result
print(result)

# Close the webdriver
driver.close()

This code will open the calculator app in a new Firefox window, enter the number "5" into the input field, click the square button, and then get the result from the output field. The result will be printed to the console.

Note: This code is just an example and may not work as-is. You will need to modify it to fit your specific needs and ensure that it is compatible with your version of Firefox and the calculator app you are using. Additionally, you will need to have the Selenium library installed and imported in your Python script.
πŸ˜ƒ: Write the same app but using native calc.exe app from windows and winum driver for selenium
πŸ€–: Here is an example of how you could write a code starting calculator app in Windows using the native calc.exe app and the Winium driver for Selenium:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Create a new instance of the Winium driver
driver = webdriver.Winium(executable_path='C:\Windows\System32\calc.exe')

# Navigate to the calculator app
driver.get("C:\Windows\System32\calc.exe")

# Enter the number to square
driver.find_element_by_name("number").send_keys("5")

# Click the square button
driver.find_element_by_name("square").click()

# Get the result
result = driver.find_element_by_name("result").text

# Print the result
print(result)

# Close the calculator app
driver.close()

This code will open the calculator app using the Winium driver, enter the number "5" into the input field, click the square button, and then get the result from the output field. The result will be printed to the console.

Note: This code is just an example and may not work as-is. You will need to modify it to fit your specific needs and ensure that it is compatible with your version of Windows and the calculator app you are using. Additionally, you will need to have the Winium driver installed and imported in your Python script.

Sign up or log in to comment