【问题标题】:Python, Firefox and Selenium 3: selecting value from dropdown does not work with Firefox 45Python、Firefox 和 Selenium 3:从下拉列表中选择值不适用于 Firefox 45
【发布时间】:2017-02-23 18:40:35
【问题描述】:

我正在尝试打开一个网站并从下拉列表中选择一个值。不幸的是,以下不起作用,经过广泛的研究,我即将放弃: Python 3.6.0 硒 3.0.2 Firefox 45.7.0(因公司规定无法更新)

我的代码是:

from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxProfile
from selenium.webdriver.support.ui import Select

#set profile for firefox
profile = FirefoxProfile("C:\\Users\\Rash\\Documents\\PythonScripts\\FirefoxProfileCopies\\u4gehg17.default.copy")
profile.set_preference("browser.download.folderList", 2)   
profile.set_preference("browser.download.manager.showWhenStarting", False)  
profile.set_preference("browser.download.dir", "C:\\Users\\Rash\\Desktop\\TestDownloadFolderSelenium")  #set directory for download
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", 'application/vnd.ms-excel')

#start a browser session
browser = webdriver.Firefox(profile)

# open the ProCon page
browser.get("http://reiseauskunft.bahn.de/bin/query.exe/dn?getstop=1&dbkanal_008=L01_S01_D001_KLR0011_konzernportal_LZ03")

select1 = Select(browser.find_element_by_name("REQ0HafasChangeTime"))
select1.select_by_visible_text("mindestens 30 Minuten")

for row in select1.options:
    print(row.text)

奇怪的是,循环从正确的下拉菜单中打印出所有正确的值,但 selectcode 无法将下拉菜单更改为值“mindestens 30 Minuten”。同样的问题也出现在不同的网站上。这可能是由于旧版本的 Firefox 造成的问题吗?

我在家里尝试使用 Firefox 51.0.1 并且成功了!它选择了正确的值。所以我现在想知道,由于我无法在工作中更新我的 Firefox,我该怎么办?我是否需要降级 Selenium 或 geckodriver?

【问题讨论】:

  • 据我所知,Geckodriver 与 Firefox 45 不完全兼容。因此,最安全的选择是将 Selenium 降级到 2.53.1。
  • 我刚刚做了,这解决了我的问题。我只是想知道我是否理解正确:Selenium 2.53 不使用 Geckodriver 但 Selenium 3.x 使用?也请将此添加为答案,以便我接受。谢谢!!

标签: python selenium firefox geckodriver


【解决方案1】:

据我所知,Geckodriver 与 Firefox 45 不完全兼容。因此,最安全的选择是将 Selenium 降级到 2.53.1。

从评论中回答您的问题。
这有点复杂。 Selenium 3 需要 Geckodriver 才能与 Firefox 通信,而后者又只能与 Firefox 47 或更高版本完全兼容(不幸的是我没有找到完整的兼容性列表)。
如果您想(或必须)使用 Firefox 45,则不能使用需要 Geckodriver 才能与 Firefox 配合使用的 Selenium 版本。
所以 FF45 == 没有 Geckodriver == 任何低于 3 的 Selenium 版本。

This post 可能会为您提供更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    相关资源
    最近更新 更多