Failed to control jquery with captcha slider using Selenium Webdrive?

I want to record the captcha slider specified on our client website.

We got this concept from another site called http://www.fmylife.com/signup

It has a captcha slider for registering.

I am trying to use the selenium webdriver action constructor

public class TestFmylife { WebDriver driver; Selenium selenium; @BeforeMethod public void startSelenium() { driver = new FirefoxDriver(); selenium = new WebDriverBackedSelenium(driver, "http://www.fmylife.com/"); driver.manage().window().maximize(); } @AfterMethod public void stopSelenium() { driver.close(); } @Test public void testFmylife() { selenium.open("/"); selenium.click("link=Sign up"); selenium.waitForPageToLoad("30000"); selenium.type("name=login", "testfmylife"); selenium.type("name=pass", " 123@fmylife "); selenium.type("name=passc", " 123@fmylife "); selenium.type("name=mail", " testfmylife@gmail.com "); Point MyPoint= driver.findElement(By.xpath("//*[@id='bgSlider']")).getLocation(); WebElement someElement = driver.findElement(By.xpath("//*[@id='bgSlider']")); System.out.println(MyPoint.x+"--------"+MyPoint.y); Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(someElement).moveByOffset(MyPoint.x,(MyPoint.y + 100)).release().build(); dragAndDrop.perform(); selenium.click("css=div.form > div.ok > input[type=\"submit\"]"); } } 

But I can not move the slider using this code

Help me figure this out

+2
source share
3 answers

I used the dragAndDropBy method of the Actions class (java.lang.Object org.openqa.selenium.interactions.Actions) and moved the slider 200 points horizontally. Try the following code:

 WebDriver driver = new FirefoxDriver(); driver.get("http://www.fmylife.com/signup"); WebElement slider = driver.findElement(By.xpath(".//*[@id='Slider']")); Actions builder = new Actions (driver); builder.dragAndDropBy(slider, 200, 0).build().perform(); 
0
source
 Actions builder = new Actions(driver); Action dragAndDrop = builder.clickAndHold(someElement) .moveToElement(otherElement) .release(otherElement) .build(); dragAndDrop.perform(); 

more can be found at http://code.google.com/p/selenium/wiki/AdvancedUserInteractions

You can use the locator as follows:

 String xto=Integer.toString(LocatorTo.getLocation().x); String yto=Integer.toString(LocatorTo.getLocation().y); 

Work Code -

 WebDriver driver = new InternetExplorerDriver(); driver.get("http://jqueryui.com/demos/slider/"); //Identify WebElement WebElement slider = driver.findElement(By.xpath("//div[@id='slider']/a")); //Using Action Class Actions move = new Actions(driver); Action action = move.dragAndDropBy(slider, 30, 0).build(); action.perform(); driver.quit(); 

Source - https://gist.github.com/2497551

0
source

If your slider is similar to mine

enter image description here

using the "sliders" (tag <a / "> as a field with the value" 5ft 5 ") in the" track slider "(tag <div> as a long black bar), then the following C # code will work to move the slider to percent along the slider track.

 public void SetSliderPercentage(string sliderHandleXpath, string sliderTrackXpath, int percentage) { var sliderHandle = driver.FindElement(By.XPath(sliderHandleXpath)); var sliderTrack = driver.FindElement(By.XPath(sliderTrackXpath)); var width = int.Parse(sliderTrack.GetCssValue("width").Replace("px", "")); var dx = (int)(percentage / 100.0 * width); new Actions(driver) .DragAndDropToOffset(sliderHandle, dx, 0) .Build() .Perform(); } 
0
source

All Articles