微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

selenium-绕过登录

第一种方式:chrome-debug

1.现在终端输入一下命令,启动Chrome-debug模式
    #windows
    chrome.exe --remote-debugging-port=9999
    #mac
    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -remote-debugging-port=9999
2.代码中实现
import allure
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestHomework:
    # 初始化driver
    def setup_method(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.debugger_address = "127.0.0.1:9999"
        self.driver = webdriver.Chrome(options=chrome_options)

        self.driver = webdriver.Chrome()
        with allure.step("打开testerhome"):
            self.driver.get("https://testerhome.com")
            self.driver.implicitly_wait(10)

    def teardown_method(self):
        self.driver.quit()
    def test_info(self):
        self.driver.find_element(By.CSS_SELECTOR,"#main-nav-menu a[href*='topics']").click()

第二种方式:通过添加cookie

import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import webdriverwait


class TestCookies:
    def setup(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(3)
        self.driver.get("https://work.weixin.qq.com/wework_admin/frame#contacts")
        cookies = {
            "wwrtx.vst": "19NQ2XtpdMSwwUH6pWX7FsQzCBGQ_ykd68GEdTXYEInKF0mAkFlqMjtJJBakRbMlU5-domydDDsxm9kZtTuBysvewHAXBOF02zONgDyGs9Qxt0NWzvpODJ8Jh_9sFWKXv08JKGe0LEeg-U3DjZcYjmtuXpnMC3sSeFzqM6XMzK7A91NwrcQyghDmlIPNJwNA2I_zfxvIWhi-EVAQzFJwMs2cxfNh5tqeE6SuCYp2N58NjF93c9b1xSkH4BVuwTsjNDzxWd2lh01VfQsWEgerBg","wwrtx.d2st": "a3327543","wwrtx.sid": "5KLjjmW-aMstJ0AquQESE7Zesy2gaWElilhy_KxvWmOlq7vkFbDlwaBDVCwcvyzE","wwrtx.ltype": "1","wxpay.corpid": "1970324954080438","wxpay.vid": "1688851903656484",}
        for k,v in cookies.items():
            self.driver.add_cookie({"name": k,"value": v})

        self.driver.get("https://work.weixin.qq.com/wework_admin/frame#contacts")

    def teardown(self):
        time.sleep(3)
        self.driver.quit()

    def test_01(self):
        webdriverwait(self.driver,5).until(
            expected_conditions.visibility_of_element_located((By.CSS_SELECTOR,".ww_operationBar:first-child "
                                                                                ".js_add_member")))

        self.driver.find_element(By.CSS_SELECTOR,".ww_operationBar:first-child .js_add_member").click()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐