package com.mavlushechka.a1qa.elements; import com.mavlushechka.a1qa.driverUtils.ActionUtils; import com.mavlushechka.a1qa.utils.DoubleUtils; import com.mavlushechka.a1qa.utils.LoggerUtils; import org.openqa.selenium.By; import org.openqa.selenium.Point; import org.openqa.selenium.WebElement; public class Slider extends BaseElement { public Slider(By locator, String name) { super(locator, name); } public void slideTo(int percentage) { WebElement slider = findElement(); Point currentPoint = new Point((int) Math.round(DoubleUtils.getPercentageOf(slider.getSize().getWidth(), getValue())-getDimension().width/2.0), 0); Point expectedPoint = new Point((int) Math.round(DoubleUtils.getPercentageOf(slider.getSize().getWidth(), percentage)-getDimension().width/2.0), 0); LoggerUtils.info("Sliding on the \"" + getName() + "\" element."); ActionUtils.dragAndDrop(slider, currentPoint, expectedPoint); } public int getValue() { return Integer.parseInt(findElement().getAttribute("value")); } }