使用selenium 操作 electron 应用

2022-10-26  本文已影响0人  no_more_pie

Electron打包的桌面版程序其实是一个web的页面,只是加了一个Electron外壳,把web页面给包起来。

使用selenium 操作 electron 应用【预研结果:success】

方式1:打开exe应用

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

options = webdriver.ChromeOptions()
options.binary_location = r"C:\Program Files\RDTestClient\RDTestClient.exe"
driver = webdriver.Chrome(chrome_options=options)
print (driver.page_source)

方式2:使用selenium远程操作已经打开的electron应用

步骤1:到应用(.exe)文件所在路径下,打开cmd窗口
步骤2:然后输入:RDtestClient.exe --remote-debugging-port=9527 --user-data-dir=“F:\selenium\AutomationProfile” ,并回车。这句代码的意思是启动 chrome浏览器 的调试模式,

from selenium import webdriver
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
options.add_experimental_option("debuggerAddress","127.0.0.1:9527")
driver = webdriver.Chrome(chrome_options=options)
#打印控制的窗口
print (driver.page_source)
driver.find_element(By.XPATH,'//div[@title="组网编辑" ]').click()

参考文献
https://blog.csdn.net/qihoo_tech/article/details/122465433

上一篇 下一篇

猜你喜欢

热点阅读