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()
  • 相关阅读:
    Spring 声明式事务管理(11)
    Spring JdbcTemplate详解(9)
    Spring 基于xml配置方式的AOP(8)
    Spring AspectJ 切入点语法详解(7)
    Spring 基于Aspectj切面表达式(6)
    spring AOP 编程--AspectJ注解方式 (4)
    Spring 切面优先级(5)
    Spring 泛型依赖注入(3)
    python反射/自省 (目前是转载)
    flask_requirements
  • 原文地址:https://www.cnblogs.com/dongliping/p/11400584.html
Copyright © 2011-2022 走看看