1

I have a problem using Selenium Webdriver (version 2.32.0) and Firefox (21.0), trying to change the values on a slider.

I wrote a Java code like this:

private void selectGiftCardPrice() throws TestingException {
 try {
 WebElement slider = getDriver().findElement(
 By.cssSelector("div.sliderHandle"));
 Actions move = new Actions(getDriver());
 move.dragAndDropBy(slider, 90, 0);
 move.build().perform();
 sleep(4000);
 } catch (Exception e) {
 log.info(e);
 throw new TestingException("e");
 }

I tried out every code I found on the Web, every change, and it still does not work. It does not show any problem, just finds the element, and does nothing. Any idea what it is, or what can I do?

EDIT from comment:

I finally made it working with jQuery slider demo

driver.get("http://jqueryui.com/resources/demos/slider/multiple-vertical.html");
WebElement slider = driver.findElement(By.xpath("//div[1]/a[contains(@class,'ui-slider-handle')]"));‌

But it is still not working for me with jQuery UI Slider demo page using Xpath //div[@id='slider']/a. What is the problem?

Yi Zeng
33k13 gold badges99 silver badges128 bronze badges
asked Jul 9, 2013 at 11:57
5
  • Have you tried this: move.dragAndDropBy(slider, 90, 0).build().perform(); ? I've noticed a few times that when using the Actions() class its best to try and keep all actions as part of the same chain. Interrupting the chain and have 'odd' effects. Commented Jul 9, 2013 at 12:24
  • Yes, I did and it was still not working, :-(. Commented Jul 9, 2013 at 12:51
  • Piece of html, please. With slider and input Commented Jul 9, 2013 at 13:24
  • I finally made it works with the Web page driver.get("jqueryui.com/resources/demos/slider/…); and the WebElement slider = driver.findElement(By.xpath("//div[1]/a[contains(@class,'ui-slider-handle')]"));, but it is still not working for me with the example page jqueryui.com/slider and the Xpath "//div[@id='slider']/a", FireBug either finds the Xpath with FirePath, but for sure it is right. What is the problem? Commented Jul 10, 2013 at 8:47
  • Correct the xpath as //div[@id='slider']/span instead of //div[@id='slider']/a Commented Apr 26, 2016 at 10:02

2 Answers 2

1

This code works absolutely fine for me. program handles slider of website : Homeshope18.com Check it out:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.homeshop18.com/fashion-jewellery/category:15143/filter_Theme:%28%22Traditional+Wear%22+%22Cuff+%26+Kada%22+%22Daily+Wear%22+%22Maang+Tikka%22+%22Openable+Round%22+%22Round%22+%22Openable+Oval%22%29/sort:Popularity/inStock:true/?it_category=HP&it_action=JW-HPSP01&it_label=HP-HPSP01-131021235900-PD-JW-ZC-VK-SC_DiwaliFestWeddingJewellery&it_value=0");
WebElement slider = driver.findElement(By.xpath("//*[@id='slider-range']/a[1]"));
Thread.sleep(3000);
Actions moveSlider = new Actions(driver);
Action action = moveSlider.dragAndDropBy(slider, 30, 0).build();
action.perform();
maxx777
1,3301 gold badge20 silver badges39 bronze badges
answered Oct 22, 2013 at 10:29

1 Comment

Nice. It's working but I cannot control the number of units to move.
0

Using Actions class, firs use clickAndHold("WebElemnt");

Then to move horizontally we need to move in the Y direction of the screen so we can use movebyoffset, i.e X-axis: 0 & Y axis: 40px

To move vertically we need to move in the X direction of the screen so we can use movebyoffset, i.e X-axis: 40px & Y axis: 0

The sample code would be :

Actions slider=new Actions(driver);
slider.clickAndHold("WebElemnt");
slider.movebyoffset(0,40).build.perform();
Eric Aya
70.1k36 gold badges190 silver badges266 bronze badges
answered Jan 9, 2018 at 8:41

Comments

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.