Python, Firefox and Selenium 3: selecting value from dropdown does not work with Firefox 45

情到浓时终转凉″ 提交于 2019-12-13 07:04:01

问题


I am trying to open a website and select a value from a dropdown. Unfortunately the below does not work and after extensive research I am about to give up: Python 3.6.0 Selenium 3.0.2 Firefox 45.7.0 (can't update due to company regulations)

My code is:

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)

The weird thing is that the loop prints all the correct values from the correct dropdown menu but the selectcode does not work to change the dropdown to the value "mindestens 30 Minuten". The same problem occurs on different websites as well. Is this maybe a problem due to an older version of firefox?

I tried at home with Firefox 51.0.1 and it worked! It selected the right values. So I now wonder, since I can not update my Firefox at work, what can I do? Do I need to downgrade Selenium or geckodriver?


回答1:


As far as I know Geckodriver is not fully compatible with Firefox 45. So your safest bet would be to downgrade Selenium to 2.53.1.

To answer your question from the comment.
It's a bit complicated. Selenium 3 needs Geckodriver to communicate with Firefox, which in turn is only fully compatible with Firefox 47 or later (unfortunately I didn't find a full compatibility list).
If you want (or have) to use Firefox 45 you cannot use a Selenium version that needs Geckodriver to work with Firefox.
So FF45 == no Geckodriver == any Selenium version below 3.

This post might give you more information.



来源:https://stackoverflow.com/questions/42423691/python-firefox-and-selenium-3-selecting-value-from-dropdown-does-not-work-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!