Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
57 views
in Technique[技术] by (71.8m points)

How to run Explorer independently with Python Selenium

I'm trying to use IE using the selenium module in python.

I want to log in with different login IDs in multiple IE windows, but the login information in IE windows is shared with each other, so independent login is not possible.

I am using selenium version is 3.6 and the explorer version is 11.

How can I fix it?

For example, when I log in to Google email in the first explorer window, when the second explorer window is turned on, I am already logged in to the Google email.

I want to log in to the same site with a different ID at the same time.

IE_1 =  ID_1 
IE_2 =  ID_2
IE_3 =  ID_3
....  
question from:https://stackoverflow.com/questions/65947876/how-to-run-explorer-independently-with-python-selenium

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can achieve separate logins by running the browser in "private" mode. This is not specific to IE. You can do this in Chrome Firefox, and other browsers as well.

1. IE in private mode

From the docs, you can set "IE Command-Line Options".

Example below is directly from the documentation. I have NOT tested the below code myself as I don't have IE in my environment.

from selenium import webdriver

options = webdriver.IeOptions()
options.add_argument('-private')
options.force_create_process_api = True
driver = webdriver.Ie(options=options) # MIGHT WANT TO CHANGE

# Navigate to url
driver.get("http://www.google.com")

driver.quit()

If you don't have the $PATH set for IE, try this:

driver = webdriver.ie(executable_path="<YOUR_IE_PATH>", 
                      options=options)

2. Chrome in private mode

For Chrome, I can confirm it is valid working code. It's a simplified version of what I use myself.

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")

driver = webdriver.Chrome(
    executable_path="<YOUR_CHROME_DRIVER_PATH>", 
    chrome_options=chrome_options)
driver.get('https://google.com')

For the full list of acceptable "chrome_options", you can check out the reference. This link may not look "official", but it's actually referenced from the Chromedriver website (under "Recognized Capabilities" - "ChromeOptions object" - "args"), so we can safely rely on this doc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...