• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

浏览器 和 浏览器驱动 版本不一致报错和解决

武飞扬头像
ALtimeAshes
帮助1

C:\Program Files\Internet Explorer

C:\Users\Administrator\AppData\Local\Google\Chrome\Application

D:\Program Files (x86)\Mozilla Firefox

D:\Programs\Python\Python38-32\
需要下载各个浏览器对应得驱动程序,放到对应的浏览器安装路径 和 python 的安装路径中。

另外,要用命令行run python程序,需要把python的安装路径添加到系统的环境变量Path中,否则,用命令 D:\PycharmProjects\pythonProject>python python_org_search.py 运行时会报错:

'python' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

Chrome报错:

1. (Session info: chrome=70.0.3538.102)
(Driver info: chromedriver=2.6.233026,platform=Windows NT 6.3 x86_64)

2. AttributeError: 'WebElement' object has no attribute 'send_keys'

解决:

check chrome version(chrome://version in browser)

下载对应版本的chromedriver.exe

(下载地址:http://chromedriver.storage.谷歌apis.com/index.html)

将下载的文件放到python的安装路径的Scripts D:\Programs\Python\Python38-32\Scripts

和 谷歌的安装路径Application中

C:\Users\acer\AppData\Local\Google\Chrome\Application\96.0.4664.110

重新运行代码就好

3. selenium.common.exceptions.WebDriverException: Message: invalid argument: unrecognized capability: chromeOptions

解决: 升级selenium版本,pip install -U selenium
D:\Programs\Python\Python38-32\Scripts>pip install -U selenium

升级完重新运行脚本就好了。

IE

使用IEDriverServer.exe驱动IE11,实现自动化测试 - feiquan - 博客园

先在打开的“程序和功能”页,点击左侧的“打开或关闭windows功能,打开或关闭IE浏览器。

1. selenium.common.exceptions.WebDriverException: Message: 'pythonProjectIEDriverServer.exe' executable needs to be in PATH. Please download from

2. https://www.selenium.dev/downloads/ and read up at https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

解决:下载IE对应版本的 IEDriverServer.exe,然后分别放到python 和 ie 的安装路径中

D:\Programs\Python\Python38-32\

C:\Program Files\Internet Explorer

C:\Users\acer\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories

3. Browser zoom level was set to 125%. It should be set to 100%

   解决: ie浏览器 - 设置 - 缩放 - 改成100%5.

4. AttributeError: 'dict' object has no attribute 'send_keys'

  解决:原因是 ie 和 IEDriverServer.exe 版本号不一致报错,需要重新下载和 ie 相同版本的驱动

5. selenium.common.exceptions.WebDriverException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070002 ('系统找不到指定的文件。') for URL 'http://localhost:50120/'

解决:原因是在系统中,禁用了IE,需要把IE启用(在控制面板中)。

6. python打不开IE浏览器

   Internet 选项 - 安全 - 四个区域都启用安全模式

7. Message: Command not found: POST

driver = webdriver.Ie()
driver.get("https://www.百度.com/")
form_textfield = driver.find_element(By.ID, 'kw')
form_textfield.clear()
form_textfield.send_keys('test')

form_textfield.submit()

运行到最后一行时报错:
selenium.common.exceptions.WebDriverException: Message: Command not found: POST /session/ef32e41e-b3ec-4d25-a5c5-8fa61125f32a/execute/sync

原因及解决:
# submit() function do not work in Ie, u can use send_keys(Keys.RETURN) instead, but u need to import Keys first.
# The Keys class provide keys in the keyboard like RETURN, F1, ALT etc.
# driver.implicitly_wait()
学新通
from selenium.webdriver.common.keys import Keys

另外,

对于python3中废弃的方法 find_element_by_id,可以用 find_element(By.ID, ‘’)代替,但需要先导入By ( from selenium.webdriver.common.by import By )

VaLGh

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfiaii
系列文章
更多 icon
同类精品
更多 icon
继续加载