美文网首页
使用selenium 操作 electron 应用

使用selenium 操作 electron 应用

作者: no_more_pie | 来源:发表于2022-10-26 16:55 被阅读0次

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浏览器 的调试模式,

  • user-data-dirr=“F:\selenium\AutomationProfile” 是在单独的配置文件中启动 chrome浏览器,可以理解为 新的浏览器,记得创建对应文件夹哦;
  • 其中 9527 为端口号,可自行指定。
    步骤2如果成功,会看到已经打开新的应用窗口。然后就可以使用selenium来控制了
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

相关文章

网友评论

      本文标题:使用selenium 操作 electron 应用

      本文链接:https://www.haomeiwen.com/subject/msopzrtx.html