为什么程序总是打开http://--port=57883/ using IEDriverServer IE through Selenium Python
Why does the program always open http://--port=57883/ using IEDriverServer IE through Selenium Python
代码试验:
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 的 DWORD(均为 32 位)值,值为 0
executable_path
executable_path 是参数,用户可以通过该参数传递 IEDriverServer 二进制文件的 绝对路径 覆盖 用于启动 IE 会话的 IEDriverServer 二进制文件的系统路径。
因此在调用 Key executable_path 时,而不是传递 绝对路径的iexplore.exe
你需要传递绝对路径的IEDriverServer.exe
如下:
browser = webdriver.Ie(executable_path=r'C:\Utility\BrowserDrivers\IEDriverServer.exe')
get()
方法必须具有 url 中的协议。所以你应该改变:
url = 'www.google.com'
至:
url = 'http://www.google.com'
代码试验:
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 的 DWORD(均为 32 位)值,值为 0
executable_path
executable_path 是参数,用户可以通过该参数传递 IEDriverServer 二进制文件的 绝对路径 覆盖 用于启动 IE 会话的 IEDriverServer 二进制文件的系统路径。
因此在调用 Key executable_path 时,而不是传递 绝对路径的iexplore.exe
你需要传递绝对路径的IEDriverServer.exe
如下:
browser = webdriver.Ie(executable_path=r'C:\Utility\BrowserDrivers\IEDriverServer.exe')
get()
方法必须具有 url 中的协议。所以你应该改变:
url = 'www.google.com'
至:
url = 'http://www.google.com'