使用步骤:

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','//*[@>))).click()

        sleep(3)

if __name__ == '__main__':
    TestCase()

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

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2021-12-14
  • 2021-12-01
  • 2021-12-22
猜你喜欢
  • 2021-10-13
  • 2021-12-03
  • 2022-01-04
  • 2021-11-08
  • 2021-05-17
  • 2021-09-09
相关资源
相似解决方案