简体   繁体   中英

Python Selenium Internet Explorer scripts don't work

If I make a simple script like this:

from selenium import webdriver
from selenium.webdriver.ie.service import Service
import os
from pathlib import Path

path = Path().absolute()
path = os.path.join(path, 'IEDriverServer')
driver = webdriver.Ie(executable_path=path)
driver.get('https://www.google.com/')
print("ANYTHINGGG")

Selenium opens the Edge on IE mode (no problem), opens google, but after that it stops... don't print "ANYTHINGGG" and I cannot program anything after driver.get('https://www.google.com/') .

This problem seems to be in any site.

Anyone has a clue of what can solve that?

(I am using windows 10, python 3.7.9)

Just expect that the code do not stops on driver.get('https://www.google.com/')

If you want to automate Edge IE mode with IEDriver, you need to:

  1. Define Inte.netExplorerOptions with additional properties that point to the Microsoft Edge browser.
  2. Start an instance of Inte.netExplorerDriver and pass it Inte.netExplorerOptions . IEDriver launches Microsoft Edge and then loads your web content in IE mode.

You also need to meet the Required Configuration . For detailed information about using Inte.net Explorer Driver to automate IE mode in Edge, you can refer to this doc .

Your code seems not right, you can refer to the following code, it works well (change the path in the code to your owns):

from selenium import webdriver
from selenium.webdriver.ie.service import Service

ser = Service("E:\\webdriver\\IEDriverServer.exe")
ieOptions = webdriver.IeOptions()
ieOptions.add_additional_option("ie.edgechromium", True)
ieOptions.add_additional_option("ie.edgepath",'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')
driver = webdriver.Ie(service = ser, options=ieOptions)

driver.get('https://www.google.com/')
print("ANYTHINGGG")

在此处输入图像描述

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