sprogissd sprogissd - 9 months ago 39
Python Question

Can't use drag_and_drop to move slider with Selenium Webdriver

I am trying to use the following code to move a slider with Selenium Webdriver, but I get an error that says: "selenium.common.exceptions.WebDriverException: Message: POST /session/38618f26-c271-41f3-a019-990ee2558063/moveto did not match a known command"

I use selenium 3.0.2 and Firefox 51.0.1 What am I doing wrong? How else can I move a slider?

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

browser = webdriver.Firefox()
browser.get("http://url_wuth_a_slider")

source_element = browser.find_element_by_xpath("xpath_to_slider_knob")
destination_element = browser.find_element_by_xpath("xpath_to_destination")
ActionChains(browser).drag_and_drop(source_element, destination_element).perform()

Answer Source

This is a known issue with the selenium bindings and geckodriver. It seems to work fine in Chrome. It may work in Firefox if you disable marrionette (but you may need to use a version of Firefox pre-50):

browser = webdriver.Firefox(capabilities = { "marionette": False })

But your best bet is Chrome.