Scenario :
Launch http://w ww.myntra.com/men-deals?f=price%3A399%2C1999.
On the left pane,on the slider for price range , Click and hold the left button and move it right to an offset of say, 150.
Note:
This can be done using two methods :
1.clickAndHold(webelement).moveByOffset(x, y)
2.dragAndDropBy(webelement,x, y)
In our case the offset 'y' will be 0, as we just want to move the slider horizontally.We set the limit for 'y' when a vertical movement of the element is needed.
Hence, we set the offset for 'x' as 150 - to move horizontally
Let's see how this can be done.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class MoveByOffsetDemo {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.myntra.com/men-deals?f=price%3A399%2C1999");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement we = driver.findElement(By.className("from"));
Actions act = new Actions(driver);
act.clickAndHold(we).moveByOffset(150, 0).build().perform();
// act.dragAndDropBy(we,150, 0).build().perform();Even this will work
Thread.sleep(5000l);
driver.quit();
}
}
Launch http://w ww.myntra.com/men-deals?f=price%3A399%2C1999.
On the left pane,on the slider for price range , Click and hold the left button and move it right to an offset of say, 150.
Note:
This can be done using two methods :
1.clickAndHold(webelement).moveByOffset(x, y)
2.dragAndDropBy(webelement,x, y)
In our case the offset 'y' will be 0, as we just want to move the slider horizontally.We set the limit for 'y' when a vertical movement of the element is needed.
Hence, we set the offset for 'x' as 150 - to move horizontally
Let's see how this can be done.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class MoveByOffsetDemo {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.myntra.com/men-deals?f=price%3A399%2C1999");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement we = driver.findElement(By.className("from"));
Actions act = new Actions(driver);
act.clickAndHold(we).moveByOffset(150, 0).build().perform();
// act.dragAndDropBy(we,150, 0).build().perform();Even this will work
Thread.sleep(5000l);
driver.quit();
}
}
Pay It
Forward...
Lots
of energy ..
DR