I have a small test case:
- Open the browser
- Enter the URL "http://practice.automationtesting.in/shop/"
- Adjust the filter by price between 150 to 450.
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
-
It seems you can find the slider simply by using class name (ui-slider-handle). What is the result when you run your code?João Farias– João Farias2019年07月22日 19:33:04 +00:00Commented 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.rodut– rodut2019年07月23日 05:48:40 +00:00Commented Jul 23, 2019 at 5:48
1 Answer 1
It seems you can find the slider simply by using class name:
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
-
It's working just fine. Thank you.rodut– rodut2019年07月23日 06:49:05 +00:00Commented Jul 23, 2019 at 6:49
-
Most welcome rodut. Could you mark the answer as accepted? It really motivates contributors.João Farias– João Farias2019年07月23日 06:56:53 +00:00Commented Jul 23, 2019 at 6:56
-
default