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

问题描述 投票:0回答:1

我正在尝试使用python中的硒在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()

将不胜感激!

python selenium internet-explorer
1个回答
0
投票

我建议您可以参考下面的示例以私有模式启动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)

如果问题仍然存在,请尝试提供有关该问题的详细信息,例如您使用的是哪个IE版本,Selenium版本,等等。>>

© www.soinside.com 2019 - 2024. All rights reserved.