• 使用Selenium控制已经打开的浏览器


    有时候网站需要扫码登录,使用Selenium启动的浏览器进程可能没法完成登录。这时候就需要手动扫码登录后,再用Selenium进行操作。

    操作步骤

    1、找到本地安装的浏览器启动路径,例如Chrome

    C:Program Files (x86)GoogleChromeApplication

    2、通过命令行启动ChromeDbug模式

    C:Program Files (x86)GoogleChromeApplication>chrome.exe --remote-debugging-port=9222

    快捷切换到该目录下(按住shift+鼠标右键)

    3、连接调试开关打开的chrome

    options = webdriver.ChromeOptions()
    options.debugger_address = "127.0.0.1:9222"
    self.driver = webdriver.Chrome(options=options)

    企业版微信登录

    先执行命令启动ChromeDbug模式

    扫码登录企业微信

    使用Selenium点击通讯录进入通讯录页面

     1 # -*- coding: utf-8 -*-
     2 from selenium import webdriver
     3 from selenium.webdriver.common.by import By
     4 class TestWX:
     5 # 初始化,控制Chrome
     6     def setup_method(self):
     7         options = webdriver.ChromeOptions()
     8         options.debugger_address = "127.0.0.1:9222"
     9         self.driver = webdriver.Chrome(options=options)
    10         self.url = "https://work.weixin.qq.com/wework_admin/frame#index"
    11         self.driver.get(self.url)
    12         self.driver.implicitly_wait(10)
    13 # 关闭浏览器
    14 #     def teardown_method(self):
    15 #         self.driver.quit()
    16     def test_a(self):
    17 # 点击通讯录
    18         self.driver.find_element(By.XPATH, '//*[@id="menu_contacts"]/span').click()
    19         
    20 a=TestWX()
    21 a.setup_method()
    22 a.test_a()
  • 相关阅读:
    springboot集成kafka
    elasticsearch http 搜索 测试
    linux下安装Elasticsearch
    laravel_admin 使用
    laravel 数据操作
    Win10+apache+PHP+Mysql
    laravel 坑(一)
    下载CentOS镜像
    window10 家庭版 添加Hyper-V虚拟机
    Win10 Composer 下载安装
  • 原文地址:https://www.cnblogs.com/dongliping/p/11400584.html
Copyright © 2020-2023  润新知