/// <summary> /// Locates a list item by its title (exact match) and taps it. </summary> /// <param name="title"> The list item's title text </param> public virtual void SelectItem(string title) { var locator = OpenQA.Selenium.By.XPath( "descendant::div[contains(@class, 'list-item-title') and text() = '" + title + "']/ancestor::li"); IWebElement item = ContentElement.FindElement(locator); Tap(Driver.WebDriver, item); }
/// <summary> /// Locates a list item by its position and taps it. </summary> /// <param name="index"> The list item's index </param> public virtual void SelectItem(int?index) { index++; //xpath's position() is 1-based var locator = OpenQA.Selenium.By.XPath("descendant::li[contains(@class, 'list-item') and position() = " + index + "]"); IWebElement item = ContentElement.FindElement(locator); Tap(Driver.WebDriver, item); }
/// <summary> /// Scrolls the area in the specified direction until the locator finds a child /// widget. The locator will be executed in the scroll area's context, so /// a relative locator should be used, e.g. <code>By.Qxh("*\/[@label=Foo]")</code> /// </summary> /// <param name="direction"> "x" or "y" for horizontal/vertical scrolling </param> /// <param name="locator"> Child widget locator </param> /// <returns>The matching child widget.</returns> public virtual IWidget ScrollToChild(string direction, OpenQA.Selenium.By locator) { Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100); IWebElement target = null; try { target = ContentElement.FindElement(locator); } catch (NoSuchElementException) { } if (target != null && IsChildInView(target).GetValueOrDefault(false)) { return(Driver.GetWidgetForElement(target)); } long?singleStep = GetScrollStep(direction); long?maximum = GetMaximum(direction); long?scrollPosition = GetScrollPosition(direction); while (scrollPosition < maximum) { // Virtual list items are created on demand, so query the DOM again try { target = ContentElement.FindElement(locator); } catch (NoSuchElementException) { } int to; if (target != null && IsChildInView(target).GetValueOrDefault(false)) { // Scroll one more stop after the target item is visible. // Without this, clicking the target in IE9 and Firefox doesn't // work sometimes. to = (int)(scrollPosition + singleStep); ScrollTo(direction, to); Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(4); return(Driver.GetWidgetForElement(target)); } to = (int)(scrollPosition + singleStep); ScrollTo(direction, to); scrollPosition = GetScrollPosition(direction); } // TODO: Find out the original timeout and re-Apply it Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(4); return(null); }
/// <summary> /// Finds the first selectable TreeNode widget with a label matching the regular /// expression and returns it /// </summary> /// <param name="regex">The regular expression to match.</param> /// <returns>The matching TreeNode.</returns> public virtual IWidget GetSelectableItem(string regex) { QX.By itemLocator = QX.By.Qxh("*/[@label=" + regex + "]"); IWebElement target = null; try { target = ContentElement.FindElement(itemLocator); } catch (NoSuchElementException) { } if (target != null) { return(Driver.GetWidgetForElement(target)); } return(null); }
/// <summary> /// Drags this widget by the specified offsets </summary> /// <param name="x"> Amount of pixels to move horizontally </param> /// <param name="y"> Amount of pixels to move vertically </param> /// <param name="step"> Generate a move event every (step) pixels </param> public override void Track(int x, int y, int step) { IWebElement element = ContentElement.FindElement(OpenQA.Selenium.By.XPath("div")); Track(Driver.WebDriver, element, x, y, step); }