import time
from selenium.webdriver.common.by import By
'''
复用已有浏览器:配置步骤
1.需要退出当前所有的谷歌浏览器(特别注意)
windows:关闭谷歌浏览器进程
2.输入启动命令,通过命令启动谷歌浏览器
windows: chrome --remote-debugging-port=9222
mac: Googlel\Chrome --remote-debugging-port=9222
1.找到chrome的启动路径
2.配置环境变量
3会证旦不户动成功
'''
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
class TestDemo:
def setup(self):
# 定义配置的实例对象option
option = Options()
# 修改实例属性为debug模式启动的 ip+端口
option.debugger_address = "localhost:9222"
# 实例化driver的时候 添加option配置
self.driver = webdriver.Chrome(options=option)
self.driver.implicitly_wait(5)
def teardown(self) -> None:
pass
# self.driver.quit()
def test_case1(self):
# 扫码登录后注释,后续操作在当前页面进行
# self.driver.get("https://work.weixin.qq.com/wework_admin/frame")
# time.sleep(15)
#点击添加成员的操作
# self.driver.find_element_by_css_selector('[class="ww_indexImg ww_indexImg_AddMember"]').click()
#想要调试的代码
self.driver.find_element(By.CSS_SELECTOR,"//*[id='username']").send_keys("admin")
self.driver.find_element(By.ID,"memberAdd_acctid").send_keys('admin')
time.sleep(5)
# # 定义配置的实例对象option
# # option = Options()
# # # 修改实例属性为debug模式启动的 ip+端口
# # option.debugger_address = "localhost:9222"
# # # 实例化driver的时候 添加option配置
# # driver = webdriver.Chrome(options=option)
# driver=webdriver.Chrome()
# driver.get("https://work.weixin.qq.com/wework_admin/frame")
# time.sleep(15)
# driver.find_element_by_css_selector('[class="ww_indexImg ww_indexImg_AddMember"]').click()
# time.sleep(5)
UI自动化之复用浏览器 【调试脚本】
于 2023-06-30 15:00:12 首次发布