【问题标题】:Why does the program always open http://--port=57883/ using IEDriverServer IE through Selenium Python为什么程序总是通过 Selenium Python 使用 IEDriverServer IE 打开 http://--port=57883/
【发布时间】:2019-11-25 09:48:52
【问题描述】:

代码试验:

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 位)值

【问题讨论】:

标签: python selenium internet-explorer selenium-iedriver iedriverserver


【解决方案1】:

executable_path

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

所以在调用 Key executable_path 时,而不是传递 iexplore.exe 的 绝对路径 你需要通过IEDriverServer.exe的绝对路径如下:

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

【讨论】:

    【解决方案2】:

    get() 方法必须在 url 中有协议。所以你应该改变:

    url = 'www.google.com'
    

    到:

    url = 'http://www.google.com'
    

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 2018-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      相关资源
      最近更新 更多