[英]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.