[英]Move slider in Selenium Webdriver with Java and Firefox
我在使用Selenium Webdriver(版本2.32.0)和Firefox(版本21.0)时遇到问题,试图更改滑块上的值。
我写了这样的Java代码:
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");
}
我尝试了在Web上找到的每个代码,每次更改,但仍然无法正常工作。 它没有显示任何问题,只是找到了元素,什么也不做。 知道它是什么,或者我能做什么?
编辑评论:
我终于使它与jQuery滑块演示一起工作
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')]"));
但是,对于使用Xpath //div[@id='slider']/a
jQuery UI Slider演示页,它仍然不起作用。 问题是什么?
这段代码对我来说绝对不错。 程序处理网站的滑块: Homeshope18.com签出:
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();
使用Actions类, clickAndHold("WebElemnt");
使用clickAndHold("WebElemnt");
然后要水平移动,我们需要在屏幕的Y方向上移动,以便可以使用movebyoffset
,即X轴:0和Y轴:40像素
要垂直移动,我们需要在屏幕的X方向上移动,以便可以使用movebyoffset
,即X轴:40px和Y轴:0
示例代码为:
Actions slider=new Actions(driver);
slider.clickAndHold("WebElemnt");
slider.movebyoffset(0,40).build.perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.