简体   繁体   中英

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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