searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

使用selenium框架测试electron应用

2024-06-21 09:38:26
83
0

启动应用

# 设置谷歌驱动器
driver_path = r'driver\chromedriver.exe'
service = webdriver.chrome.service.Service(driver_path)
service.start()

#以下是必要设置,否则启动不了或获取不到electron应用
options.add_argument('--disable-gpu')  # fix:DevToolsActivePort file doesn't exist
options.add_argument('--disable-dev-shm-usage')  # fix:DevToolsActivePort file doesn't exist
options.add_argument('--remote-debugging-port=9222')  # fix:DevToolsActivePort file doesn't
options.binary_location = f"C:\Program Files (x86)\CtyunClouddeskUniversal\CtyunClouddeskUniversal.exe"
#设置electron应用的绝对路径
options.binary_location = f"xxx.exe"

pc_driver = webdriver.Chrome(service=service, options=options)

xpath获取元素,实现登录

user_input = pc_driver.find_elements(By.XPATH, "xxxxx")[0]
user_input.clear()
user_input.send_keys(acc)

pwd_input = pc_driver.find_elements(By.XPATH, "xxxxx")[0]
pwd_input.clear()
pwd_input.send_keys(pwd)

login_btn = pc_driver.find_elements(By.XPATH, "xxxxx')]")[0]
login_btn.click()

如果electron应用有多个窗口,注意要切换窗口,再继续操作,否则会获取不到对应元素

all_handles = pc_driver.window_handles
pc_driver.switch_to.window(all_handles[0])
0条评论
0 / 1000
麦****波
2文章数
0粉丝数
麦****波
2 文章 | 0 粉丝
麦****波
2文章数
0粉丝数
麦****波
2 文章 | 0 粉丝
原创

使用selenium框架测试electron应用

2024-06-21 09:38:26
83
0

启动应用

# 设置谷歌驱动器
driver_path = r'driver\chromedriver.exe'
service = webdriver.chrome.service.Service(driver_path)
service.start()

#以下是必要设置,否则启动不了或获取不到electron应用
options.add_argument('--disable-gpu')  # fix:DevToolsActivePort file doesn't exist
options.add_argument('--disable-dev-shm-usage')  # fix:DevToolsActivePort file doesn't exist
options.add_argument('--remote-debugging-port=9222')  # fix:DevToolsActivePort file doesn't
options.binary_location = f"C:\Program Files (x86)\CtyunClouddeskUniversal\CtyunClouddeskUniversal.exe"
#设置electron应用的绝对路径
options.binary_location = f"xxx.exe"

pc_driver = webdriver.Chrome(service=service, options=options)

xpath获取元素,实现登录

user_input = pc_driver.find_elements(By.XPATH, "xxxxx")[0]
user_input.clear()
user_input.send_keys(acc)

pwd_input = pc_driver.find_elements(By.XPATH, "xxxxx")[0]
pwd_input.clear()
pwd_input.send_keys(pwd)

login_btn = pc_driver.find_elements(By.XPATH, "xxxxx')]")[0]
login_btn.click()

如果electron应用有多个窗口,注意要切换窗口,再继续操作,否则会获取不到对应元素

all_handles = pc_driver.window_handles
pc_driver.switch_to.window(all_handles[0])
文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0