zoukankan      html  css  js  c++  java
  • python+selenium2自动化---复用已有的浏览器

    使用步骤:

    1、将Chrome浏览器安装路径添加到系统环境变量中(或者进入安装目录),执行

    chrome --remote-debugging-port=9222

    2、在步骤1打开的浏览器中登录要操作的网站;

    3、python代码如下,这样就可以免登录,直接操作已经登录的页面了:

    from time import sleep
    
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    
    class TestCase():
        def __init__(self):
            options = Options()
            options.debugger_address = '127.0.0.1:9222'
            self.driver = webdriver.Chrome(chrome_options=options)
    
            WebDriverWait(self.driver, 60, 0.5).until(
                EC.visibility_of_element_located(('xpath','//*[@id="workzone"]/div[2]/ul[1]/li[1]/div/span[2]'))).click()
    
            sleep(3)
    
    if __name__ == '__main__':
        TestCase()

    注意点,好像需要先关闭其他所有的浏览器,不然没法复用。

  • 相关阅读:
    javascript初识
    css定位及叠放次序
    css精灵图
    css元素的显示及隐藏、文字隐藏
    css浮动
    盒子模型的边框、内边距、外边距、阴影
    css背景
    css中的显示与隐藏
    css定位
    css的布局与版心布局
  • 原文地址:https://www.cnblogs.com/canghai1024/p/13490905.html
Copyright © 2011-2022 走看看