简体   繁体   English

使用 Selenium Python 在私有模式下打开 Internet Explorer

[英]Opening Internet Explorer in Private Mode with Selenium Python

I am trying to open gmail in IE using selenium in python, after the first time of logging in however, I stay logged in, this breaks my code, and I would like it to start in private mode to make sure I don't stay logged in. This is my code:我正在尝试使用 python 中的 selenium 在 IE 中打开 gmail,但是,在第一次登录之后,我保持登录状态,这会破坏我的代码,我不想让它在私人模式下启动登录。这是我的代码:

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class internet_explorer:
    def __init__(self):
        self.driver = webdriver.Ie(executable_path='venv\\Scripts\\IEDriverServer.exe')
        self.driver.get("https://gmail.com")
        time.sleep(2)
        self.driver.find_element_by_xpath("//input[@name=\"identifier\"]") \
            .send_keys(em + Keys.ENTER)
        time.sleep(1)
        self.driver.find_element_by_xpath("//input[@name=\"password\"]") \
            .send_keys(pw + Keys.ENTER)
        time.sleep(10)
        self.driver.close()
        self.driver.quit()

internet_explorer()

Help would be appreciated!帮助将不胜感激!

I suggest you can try to refer to an example below to launch the IE browser in private mode.我建议您可以尝试参考下面的示例以私有模式启动 IE 浏览器。

caps = DesiredCapabilities.INTERNETEXPLORER
caps["se:ieOptions"] = {}
caps["se:ieOptions"]['ie.forceCreateProcessApi'] = True
caps["se:ieOptions"]['ie.browserCommandLineSwitches'] ='-private'
caps["se:ieOptions"]["ie.ensureCleanSession"] = True
driver = webdriver.Ie(executable_path='C:\selenium\IEDriverServer_x64_3_8.exe', capabilities=caps)

If the issue persists then please try to provide detailed information about the issue like which IE version, Selenium version you are using, etc.如果问题仍然存在,请尝试提供有关问题的详细信息,例如您使用的是哪个 IE 版本、Selenium 版本等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM