📅  最后修改于: 2022-03-11 14:59:28.936000             🧑  作者: Mango
@Test
public void dragSlider() throws InterruptedException {
//1. Launch browser and maximize
System.setProperty("webdriver.chrome.driver", "/home/joy/Documents/Eclipse/Workspace/GETEC_Handson/mavenproject/lib/chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
//2. Navigate to destination Url
String destinationUrl = "https://jqueryui.com/slider/#rangemin";
driver.navigate().to(destinationUrl);
//3. Switch to Iframe
WebElement iframeXpath = driver.findElement(By.xpath("//div[@id='content']/iframe"));
driver.switchTo().frame(iframeXpath);
//4. Find slider tip
WebElement sliderXpath = driver.findElement(By.xpath("//div[@id='slider-range-min']/span"));
//5. Drag it
Actions act = new Actions(driver);
act.dragAndDropBy(sliderXpath, 378, 54).perform();
//6. Wait for 5 seconds
Thread.sleep(5000);
//7. close
driver.close();
}