Mike Esteghamatian Mike Esteghamatian - 26 days ago 4
Python Question

How to move range input using Selenium (in Python)?

I have been using Python Selenium for quite some time and I have been happy with it until I got this new requirement which I am supposed to set sliders on a web-page (here) to certain values and then let the page run its scripts to update the page with the results.

My problem is how to set the slider min and max knobs () using Python Selenium. I have the tried the example here and my code is below.

#! /usr/bin/python2.7
import os
import time

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
import datetime
import time
import mysql.connector



def check2(driver, slidebar, sliderknob, percent):

height = slidebar.size['height']
width = slidebar.size['width']

move = ActionChains(driver);
# slidebar = driver.find_element_by_xpath("//div[@id='slider']/a")

if width > height:
#highly likely a horizontal slider
print "off set: ", percent * width / 100
move.click_and_hold(sliderknob).move_by_offset(500, 0).release().perform()
else:
#highly likely a vertical slider
move.click_and_hold(sliderknob).move_by_offset(percent * height / 100, 0).release().perform()

driver.switch_to_default_content()

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-proxy-server')

os.environ["PATH"] += ":/home/mike/software"

os.environ["PATH"] += ":/usr/local/bin/"
try:
driver = webdriver.Chrome()
driver.get("http://99.243.40.11/#/HouseSold")
els = driver.find_elements_by_xpath('//input[@class="input high"]')
print 'els.len = ', len(els)
e = els[0]
ens = driver.find_elements_by_xpath('//span[@class="pointer high"]')
en = ens[0]
check2(driver, e, en, 70)
time.sleep(20)
finally:
driver.close()


Unfortunately not working for me.
Please let me know if you know of any clue.
Much appreicate your help.

Regards,

Answer

Well I think you can follow last comment's and it will give you the clue.

Actually I did and got some good results. First you need use Selenium IDE to find the knob you like to move and then do sth like below to move it like below.

Let me know if that helps you.

Cheers,

try:
    driver = webdriver.Chrome()
    driver.get("http://99.243.40.11/#/HouseSold")
    en =  driver.find_element_by_xpath("//span[6]")
    move = ActionChains(driver)
    move.click_and_hold(en).move_by_offset(10, 0).release().perform()
    time.sleep(5)

    move.click_and_hold(en).move_by_offset(10, 0).release().perform()
    time.sleep(5)

    move.click_and_hold(en).move_by_offset(10, 0).release().perform()
    time.sleep(5)

finally:
    driver.close()
Comments