2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PythonでWindowsアプリを自動化する【プログラム】

Last updated at Posted at 2021-07-09

環境構築が整ったらプログラミングを行います。

Python
# 必要なライブラリのインポート
from appium import webdriver
from selenium.webdriver.common.keys import Keys

# 起動されているWindows Application Driverへ接続する
# この例では、アプリケーション全体(App=Root)を対象として4999番ポートで起動されたWADへ接続している。
# 特定のアプリを起点としたい場合は、desired_caps["app"] = "C:\\hoge.exe" とする。

desired_caps = {}
desired_caps["app"] = "Root"
driver = webdriver.Remote(command_executor='http://127.0.0.1:4999', desired_capabilities= desired_caps)
	
# 要素の指定
xpath_str = \
     "/".join(['ここにWinAppDriverUiRecorderで調査したxpathを書く'])

# キー入力
driver.find_element_by_xpath(xpath_str).send_keys(キーを書く)

# クリック
driver.find_element_by_xpath(xpath_str).click()

# 文字を取得
driver.find_element_by_xpath(xpath_str).text

番外編!Pythonコードをexeファイル化する
1.pyinstallerをインストールする
pip install pyinstaller

2.pyinstallerコマンドで.pyファイルをexeファイルにする
 pyinstaller [ファイル名].py --onefile

3.成功すると実行したフォルダ下にdistフォルダが作られておりその中にexeファイルが出来る

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?