protected static void ClickAndHold(PageElement pageElement, TimeSpan?maxWaitTime = null) { pageElement.GoToFrame(); var actions = new OpenQA.Selenium.Interactions.Actions(SeleniumDriver.Driver); var onElement = SeleniumDriver.Driver.FindElement(pageElement.Locator); actions.ClickAndHold(onElement).Build().Perform(); Thread.Sleep(maxWaitTime ?? Default5Seconds); actions.Release(onElement).Build().Perform(); }
public void Invoke(LocatedElements elements) { var action = new OpenQA.Selenium.Interactions.Actions(Context.Driver); elements .ConstraintCount(c => c == 1) .Elements .ForEach(x => action .Release(x) .Perform()); }
/// <summary> /// Drags the <paramref name="sourceElement"/> to the <paramref name="destinationElement"/>. /// </summary> /// <param name="sourceElement"></param> /// <param name="destinationElement"></param> public void DragAndDrop(By sourceElement, By destinationElement) { try { var builder = new OpenQA.Selenium.Interactions.Actions(driver); builder.ClickAndHold(driver.FindElement(sourceElement)); builder.MoveToElement(driver.FindElement(destinationElement)); builder.Release(); builder.Build(); builder.Perform(); } catch (Exception e) { MyLogger.Log.Error($"Failed to drag source element: {sourceElement} to destination element: {destinationElement}. {e.Message}"); throw e; } }
public void Group_Test() { driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30)); driver.Navigate().GoToUrl(this.baseURL); driver.FindElementById("email").Clear(); driver.FindElementById("email").SendKeys("*****@*****.**"); driver.FindElementById("password").Clear(); driver.FindElementById("password").SendKeys("password"); //Thread.Sleep(2 * 1000); driver.FindElementById("submit").Click(); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("Main")); driver.FindElementById("myGroups").Click(); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("MyGroups")); driver.FindElementByClassName("navbar-brand").Click(); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("Main")); driver.FindElementById("myGroups").Click(); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("MyGroups")); SelectElement selector = new SelectElement(driver.FindElementById("groupInvites")); selector.SelectByText("Basic diagnosis (created by [email protected])"); driver.FindElementById("submit").Click(); selector = new SelectElement(driver.FindElementById("groupInvites")); selector.SelectByIndex(0); selector.SelectByIndex(1); driver.FindElementsByName("submitButton")[1].Click(); driver.FindElementById("Basic diagnosis (created by [email protected])").Click(); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("Group")); selector = new SelectElement(driver.FindElementById("TestId")); selector.SelectByIndex(0); driver.FindElementById("submit").Click(); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("Answer Question")); driver.FindElementsByName("norm")[1].Click(); IWebElement slider = driver.FindElementByName("sure1"); OpenQA.Selenium.Interactions.Actions actions = new OpenQA.Selenium.Interactions.Actions(driver); actions.ClickAndHold(slider); actions.MoveByOffset(40, 0).Build().Perform(); actions.Release(slider); driver.FindElementByClassName("TokenSearch").FindElement(By.TagName("input")).SendKeys("ca"); driver.FindElementByClassName("Dropdown").FindElement(By.TagName("li")).Click(); IWebElement slider2 = driver.FindElementByName("sure2"); actions.ClickAndHold(slider2); actions.MoveByOffset(25, 0).Build().Perform(); actions.Release(); driver.FindElementById("submit").Click(); for (int i = 1; i <= 8; i++) { driver.FindElementById("submit").Click(); } bool presentFlag = false; try { // Check the presence of alert IAlert alert = driver.SwitchTo().Alert(); // Alert present; set the flag presentFlag = true; //Thread.Sleep(3000); // if present consume the alert alert.Accept(); } catch (NoAlertPresentException ex) { Assert.IsTrue(false); } Assert.IsTrue(presentFlag); Assert.IsTrue(driver.FindElementById("meta").GetAttribute("name").Equals("Main")); driver.Close(); }
/// <summary>Releasing a held mouse button.</summary> /// <returns></returns> public Actions releaseMouse() { _actions.Release(); return(this); }