zoukankan      html  css  js  c++  java
  • 使用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()
  • 相关阅读:
    组合数学
    gcd和lcm
    快速幂
    线性求逆元
    5月月赛(* ̄︿ ̄)
    通往奥格瑞玛的道路
    Dijkstra学习笔记
    动态规划笔记(2)
    美军战略指导:《维持美国的世界领导力:21世纪国防的优先事项》
    ACM/ICPC2016沈阳网络赛(不完全)解题报告
  • 原文地址:https://www.cnblogs.com/dongliping/p/11400584.html
Copyright © 2011-2022 走看看