【发布时间】:2018-05-28 05:24:25
【问题描述】:
我想根据给定的参数值自动化Range Slider。我刚刚尝试使用Actions class,但在计算移动 xOffset 值时遇到了问题。
编写我测试过的代码。
void automateApplication( RemoteWebDriver driver ) {
driver.get( "http://rangeslider.js.org/" );
driver.manage().window().maximize();
//Thread.sleep( 1000 * 60 * 1 );
rangeSlidePointer("//div[@id='js-rangeslider-0']/div[2]", 147, 0);
System.out.println("Enter something in console to quit the browser and driver.");
try {
System.in.read();
System.in.read();
} catch (java.io.IOException e) {
e.printStackTrace();
}
driver.close();
driver.quit();
}
void rangeSlidePointer( String locator, int xOffset, int yOffset ) {
WebDriverWait explicitWait = new WebDriverWait( driver, 1000 * 60 * 2 );
By findBy = By.xpath( locator );
WebElement sliderElement = explicitWait.until(ExpectedConditions.elementToBeClickable( findBy ));
Actions moveSlider = new Actions(driver);
Action action = moveSlider.dragAndDropBy(sliderElement, xOffset, yOffset).release().build();
// Actions action = moveSlider.moveToElement(sliderElement).clickAndHold().moveByOffset(xOffset,yOffset).release();
action.perform();
}
从 Ranged 滑块应用程序中观察到。
<section id="top">
<input type="range" min="10" max="1000" step="10" value="300" data-rangeslider=""
style="position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0;">
<div class="rangeslider rangeslider--horizontal" id="js-rangeslider-0">
<div class="rangeslider__fill" style="width: 529.495px;"></div>
<div class="rangeslider__handle" style="left: 509.495px;"></div>
</div>
<output id="js-output">980</output>
</section>
var elem = $x("//div[@id='js-rangeslider-0']")[0];
var offset = elem.offsetLeft - elem.offsetParent.offsetLeft;
console.dir( offset );
var elem = $(".rangeslider__handle");
var offset = elem.offset().left - elem.parent().offset().left;
console.dir( offset );
/*
tagName|nodeName = "DIV"
clientWidth, offsetWidth, scrollWidth = 560
clientHeight, offsetHeight, scrollHeight = 30
firstChild clientWidth = 419
clientHeight = 20
lastChild clientWidth = 40
clientHeight = 40
type="range" min="10" max="1000" step="10" value="300"
update=760
*/
有关更多信息,请参阅此图片:
我需要关于XPath 或使用Actions Class 的答案,以便我可以自动化以下网址:
参考网址
https://www.hdfcbank.com/personal/personal-loan-emi-calculator https://www.icicibank.com/calculators/home-loan-emi-calculator.html https://www.kotak.com/en/calculators/personal-loan-emi-calculator.html
正如@Murthi 建议的那样,我可以使用以下代码通过更改输入字段的值来自动化http://rangeslider.js.org/。
var ele = $('input[type="range"]');
ele.val(50).change();
但我不想改变输入字段的值,只需要根据其句柄rangeslider__handle或rangeslider rangeslider--horizontal更改滑块。
【问题讨论】:
标签: java jquery html selenium slider