public void Slider(string Anstext, int target) { IWebElement slider = webDriver.FindElement(By.XPath("//div[div[div[contains(text(),'" + Anstext + "')]]]//div[contains(@id,'AnswerSlider')]//a")); OpenQA.Selenium.Interactions.Actions aa = new OpenQA.Selenium.Interactions.Actions(webDriver); aa.DragAndDropToOffset(slider, target, 0).Perform(); }
public void Test() { driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.jpcenter.ru"); driver.FindElement(By.PartialLinkText(make)).Click(); driver.FindElement(By.PartialLinkText(model)).Click(); // Wait for element driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 45)); // Grab the element and then feed it to the actions statement below. IWebElement element = driver.FindElement(By.XPath("//div[@id='aj_sl1']/div[2]/img")); IWebElement element2 = driver.FindElement(By.Id("aj_sl1")); Actions actionsProvider = new Actions(driver); actionsProvider.DragAndDropToOffset(element, -100, -100); actionsProvider.DragAndDropToOffset(element2, -100, -100); }
public void DragAndDropRelativeAndToElement() { driver.Url = dragAndDropPage; IWebElement img1 = driver.FindElement(By.Id("test1")); IWebElement img2 = driver.FindElement(By.Id("test2")); Actions actionProvider = new Actions(driver); actionProvider.DragAndDropToOffset(img1, 100, 100).DragAndDrop(img2, img1).Perform(); Assert.AreEqual(img1.Location, img2.Location); }
private Point drag(IWebElement elem, Point initialLocation, int moveRightBy, int moveDownBy) { Point expectedLocation = new Point(initialLocation.X, initialLocation.Y); expectedLocation.Offset(moveRightBy, moveDownBy); Actions actionProvider = new Actions(driver); actionProvider.DragAndDropToOffset(elem, moveRightBy, moveDownBy).Perform(); return expectedLocation; }
/// <summary> /// Handles the command. /// </summary> /// <param name="driver">The driver used to execute the command.</param> /// <param name="locator">The first parameter to the command.</param> /// <param name="value">The second parameter to the command.</param> /// <returns>The result of the command.</returns> protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string[] parts = value.Split(new string[] { "," }, 2, StringSplitOptions.None); int deltaX = int.Parse(parts[0], CultureInfo.InvariantCulture); int deltaY = int.Parse(parts[1], CultureInfo.InvariantCulture); IWebElement element = this.finder.FindElement(driver, locator); Actions actionBuilder = new Actions(driver); actionBuilder.DragAndDropToOffset(element, deltaX, deltaY).Perform(); return null; }
public void DragTooFar() { driver.Url = dragAndDropPage; IWebElement img = driver.FindElement(By.Id("test1")); // Dragging too far left and up does not move the element. It will be at // its original location after the drag. Point originalLocation = new Point(0, 0); Actions actionProvider = new Actions(driver); Assert.That(() => actionProvider.DragAndDropToOffset(img, 2147480000, 2147400000).Perform(), Throws.InstanceOf<WebDriverException>()); new Actions(driver).Release().Perform(); }
protected void MoveMainContentSplitter() { var byEle = By.Id("mainContentDetails_splitter"); WaitForElement(byEle); var element = myDriver.FindElement(byEle); var point = element.Location; //LogWriter.Write("x : " + point.X); //LogWriter.Write("y : " + point.Y); if (point.Y > 300) { var action = new OpenQA.Selenium.Interactions.Actions(myDriver); action.DragAndDropToOffset(element, 0, -150); action.Perform(); } }
public void DragSlider() { // Wait for element driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 45)); // Grab the element and then feed it to the actions statement below. IWebElement element = driver.FindElement(By.XPath("//div[@id='aj_sl1']/div[2]/img")); Console.WriteLine(element.ToString()); Console.ReadLine(); Actions actionsProvider = new Actions(driver); actionsProvider.DragAndDropToOffset(element, 50, 0); actionsProvider.ClickAndHold(element); actionsProvider.MoveByOffset(50, 0); actionsProvider.Release(element); }
public void MouseActiveLeft(double left, double right, int shift) { Actions action = new Actions(Driver); IWebElement axi = Driver.FindElement(By.Id("axis")); (Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + left + "," + right + ");"); var before = (Driver as IJavaScriptExecutor).ExecuteScript("return $(\"#axis\").axis(\"getRange\");"); var bL = Convert.ToDouble((before as Dictionary<string, object>)["left"]); var bR = Convert.ToDouble((before as Dictionary<string, object>)["right"]); action.Build(); action.DragAndDropToOffset(axi, -shift, 0); action.Perform(); var after = (Driver as IJavaScriptExecutor).ExecuteScript("return $(\"#axis\").axis(\"getRange\");"); var aL = Convert.ToDouble((after as Dictionary<string, object>)["left"]); var aR = Convert.ToDouble((after as Dictionary<string, object>)["right"]); Assert.IsTrue(aL > bL && aR > bR); }
public void DragTooFar() { driver.Url = dragAndDropPage; IWebElement img = driver.FindElement(By.Id("test1")); // Dragging too far left and up does not move the element. It will be at // its original location after the drag. Point originalLocation = new Point(0, 0); Actions actionProvider = new Actions(driver); actionProvider.DragAndDropToOffset(img, int.MinValue, int.MinValue).Perform(); Point newLocation = img.Location; Assert.LessOrEqual(newLocation.X, 0); Assert.LessOrEqual(newLocation.Y, 0); // TODO(jimevans): re-enable this test once moveto does not exceed the // coordinates accepted by the browsers (Firefox in particular). At the // moment, even though the maximal coordinates are limited, mouseUp // fails because it cannot get the element at the given coordinates. //actionProvider.DragAndDropToOffset(img, int.MaxValue, int.MaxValue).Perform(); //We don't know where the img is dragged to , but we know it's not too //far, otherwise this function will not return for a long long time }
public void DragTooFar() { driver.Url = dragAndDropPage; IWebElement img = driver.FindElement(By.Id("test1")); // Dragging too far left and up does not move the element. It will be at // its original location after the drag. Point originalLocation = new Point(0, 0); Actions actionProvider = new Actions(driver); actionProvider.DragAndDropToOffset(img, int.MinValue, int.MinValue).Perform(); Point newLocation = img.Location; Assert.That(newLocation.X, Is.LessThanOrEqualTo(0)); Assert.That(newLocation.Y, Is.LessThanOrEqualTo(0)); // TODO(jimevans): re-enable this test once moveto does not exceed the // coordinates accepted by the browsers (Firefox in particular). At the // moment, even though the maximal coordinates are limited, mouseUp // fails because it cannot get the element at the given coordinates. //actionProvider.DragAndDropToOffset(img, int.MaxValue, int.MaxValue).Perform(); //We don't know where the img is dragged to , but we know it's not too //far, otherwise this function will not return for a long long time }
private Point drag(IWebElement elem, Point initialLocation, int moveRightBy, int moveDownBy) { Point expectedLocation = new Point(initialLocation.X, initialLocation.Y); expectedLocation.Offset(moveRightBy, moveDownBy); Actions actionProvider = new Actions(driver); actionProvider.DragAndDropToOffset(elem, moveRightBy, moveDownBy).Perform(); return expectedLocation; }
public IMouseActions DragAndDropToOffset(BaseElement source, int offsetX, int offsetY) { actions.DragAndDropToOffset(source.IWebElement, offsetX, offsetY); return(this); }
public void DragTooFar() { driver.Url = dragAndDropPage; IWebElement img = driver.FindElement(By.Id("test1")); // Dragging too far left and up does not move the element. It will be at // its original location after the drag. Point originalLocation = new Point(0, 0); Actions actionProvider = new Actions(driver); actionProvider.DragAndDropToOffset(img, int.MinValue, int.MinValue).Perform(); Assert.AreEqual(originalLocation, img.Location); actionProvider.DragAndDropToOffset(img, int.MaxValue, int.MaxValue).Perform(); //We don't know where the img is dragged to , but we know it's not too //far, otherwise this function will not return for a long long time }
public static IWebElement DragToOffset(this IWebElement element, int x, int y) { var action = new Actions(WebDriverTestBase.driver); action.DragAndDropToOffset(element, x, y).Build().Perform(); return element; }
/// <summary> /// Mousedown event on the element then drag to offset. /// </summary> /// <param name="element"></param> public static void DragAndDropOffset(this IWebElement element, int x, int y) { Actions act = new Actions(Browser.Driver); act.DragAndDropToOffset(element, x, y).Perform(); }