1

I have a small test case:

I tried to use ActionChains, but no result.

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("http://practice.automationtesting.in/shop/")
driver.maximize_window()
slider = driver.find_element_by_xpath("//*[@id='woocommerce_price_filter-2']/form/div/div[1]/span[2]")
move = ActionChains(driver)
move.click_and_hold(slider).move_by_offset(10, 0).release().perform()

Can someone explain, what I'm doing wrong? Thanks.

João Farias
11.2k2 gold badges21 silver badges41 bronze badges
asked Jul 22, 2019 at 18:32
2
  • It seems you can find the slider simply by using class name (ui-slider-handle). What is the result when you run your code? Commented Jul 22, 2019 at 19:33
  • João Farias, when I use class_name("ui-slider-handle"), only the firs selector is moved. So I verified using "assert" if my slider (by xpath) is visible, and I received no error. Then I changed the last line of code: move.click_and_hold(slider).move_by_offset(-28, 0).release().perform() And I selected from range 150 to 451. Unfortunately, I can't select exactly to 450. Commented Jul 23, 2019 at 5:48

1 Answer 1

2

It seems you can find the slider simply by using class name:

enter image description here

sliders = driver.find_elements_by_class_name("ui-slider-handle") #Selecting all sliders
left_slider = sliders[0]
right_slider = sliders[1]
move = ActionChains(driver)
# Moving the left slider
move.click_and_hold(left_slider).move_by_offset(10, 0).release().perform()
# Moving the right slider
move.click_and_hold(right_slider).move_by_offset(-28, 0).release().perform()
answered Jul 23, 2019 at 6:00
3
  • It's working just fine. Thank you. Commented Jul 23, 2019 at 6:49
  • Most welcome rodut. Could you mark the answer as accepted? It really motivates contributors. Commented Jul 23, 2019 at 6:56
  • Yes, sure. Thank you. Commented Jul 23, 2019 at 8:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.