python - 为什么程序总是打开http ://--port=57883/using IEDriverServer IE through Selenium Python

标签 python selenium internet-explorer selenium-iedriver iedriverserver

代码试验:

import time
from selenium import webdriver
from selenium.webdriver.ie.options import Options
url = 'www.google.com'
def Login():
    browser = webdriver.Ie(executable_path=r'C:\Program Files\Internet Explorer\iexplore.exe')
    browser.implicitly_wait(5)
    browser.get(url)
    print(browser.title)
    browser.find_element_by_id("register").click()
    time.sleep(9)
    browser.implicitly_wait(5)
    browser.get(url)
    time.sleep(9)
    browser.quit()

Login()

当我在终端中运行这个python文件时,它总是跳转到名称为(http://--port=57583/)的页面 我不知道为什么

<小时/>

20191125添加

browser = webdriver.Ie(executable_path=r'C:\Program Files\Internet Explorer\IEDriverServer.exe')
browser.implicitly_wait(5)
browser.get(url)

当我运行这个login.py时 新的错误出现了

Traceback (most recent call last):
  File "C:/Users/ou/PycharmProjects/accessw/login.py", line 32, in <module>
    ie()
  File "C:/Users/ou/PycharmProjects/accessw/login.py", line 14, in ie
    browser.get(url)
  File "C:\Users\ou\PycharmProjects\accessw\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\ou\PycharmProjects\accessw\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\ou\PycharmProjects\accessw\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: Specified URL (www.google.com) is not valid.
<小时/>

20191126 添加

最后,我花了大约三个小时才弄清楚它出了什么问题!
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

我需要创建一个名为 iexplore.exe 且值为 0 的 DWORD(32 位)值

最佳答案

可执行文件路径

executable_path是用户可以传递IEDriverServer二进制文件的绝对路径的参数,覆盖IEDriverServer二进制文件的系统路径用于启动 IE session 。

因此,在调用 Key executable_path 时,不要传递 iexplore.exe绝对路径 您需要传递 IEDriverServer.exe绝对路径 如下:

browser = webdriver.Ie(executable_path=r'C:\\Utility\\BrowserDrivers\\IEDriverServer.exe')

关于python - 为什么程序总是打开http ://--port=57883/using IEDriverServer IE through Selenium Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59029032/

相关文章:

python - 如何在 Python 中处理命令行参数?

selenium - 如何在 Selenium 中处理 HTML Audio 元素

javascript - 使用 selenium 抓取 Tripadvisor 时如何单击 "More"按钮?

java - 当页面左右滚动时,如何在 Selenium 中捕获整个屏幕

html - 如何针对 ie7 标准定位 css

python - 如何使用 Python 2.4 解压缩文件?

python - 如何遍历和搜索 python 字典?

python - 按2列对np 2d数组进行排序(升序、降序)

asp.net-mvc - 带有 IE8 的 IIS6 无法正确加载 ASP.NET MVC 站点

javascript - EncodeURIComponent 抛出 "Object doesn' t 支持此属性或方法“错误(IE 8)