public IEnumerable <string> GetRemainingChoices() { // TODO(tthomas): Find a way to turn the retry logic into a function. IEnumerable <string> choices; ShinyUtilities.ShinyWait(driver); int tries = 3; while (true) { try { choices = from choice_div in driver.FindElements(By.XPath(this.choices)) select choice_div.GetAttribute("data-value"); break; } catch (OpenQA.Selenium.NoSuchElementException) { ShinyUtilities.ShinyWait(driver); if (--tries == 0) { throw; } } } return(choices); }
public void ToggleItem(string v, bool?select = null) { if (!selectize) { var path = this.div + "/select/option[@value='" + v + "']"; if (driver.FindElement(By.XPath(path)).Displayed) { if (select != null) { var selectElement = driver.FindElement(By.XPath(this.div + "/select")); var isSelected = (Int64)((IJavaScriptExecutor)driver).ExecuteScript( "return [].slice.call(arguments[0].selectedOptions).filter(function (option) { return option.value === arguments[1] }).length", new object[] { selectElement, v }); if ((isSelected == 1) == select) { // already selected/deselected return; } } //var original_state = driver.FindElement(By.XPath(path)).GetAttribute("selected"); driver.FindElement(By.XPath(path)).Click(); ShinyUtilities.ShinyWait(driver); //var expected_new_state = original_state == "true" ? null : "true"; //wait.Until(d => driver.FindElement(By.XPath(path)).GetAttribute("selected") == expected_new_state); } } }
public ShinySelectInput(IWebDriver driver, string id) { this.driver = driver; this.id = id; this.div = string.Format("//select[@id='{0}']/..", id); var master_div = this.driver.FindElement(By.XPath(this.div)); this.input = this.div + "/div[1]/div[1]/input"; this.choices = this.div + "/select/following::div[1]/div[2]/div[1]/div"; this.selected = this.div + "/div[1]/div[1]/div[@class='item']"; this.wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(11.0)); try { this.driver.FindElement(By.XPath(this.choices)); } catch (OpenQA.Selenium.NoSuchElementException) { // Force the choices to appear. master_div.Click(); ShinyUtilities.ShinyWait(driver); this.driver.FindElement(By.XPath(this.input)).SendKeys(Keys.Escape); ShinyUtilities.ShinyWait(driver); } if (this.driver.FindElement(By.XPath(this.choices)).GetAttribute("data-value") == null) { this.choices = string.Format("//select[@id='{0}']/following::div[1]/div[2]/div[1]/div/div[@class='option selected' or @class='option']", id); this.selected = string.Format("//select[@id='{0}']/following::div[1]/div[1]/div[@class='item']", id); } }
public void SetCurrentSelectionClicked(string v) { var master_div = driver.FindElement(By.XPath(div)); master_div.Click(); ShinyUtilities.ShinyWait(driver); IEnumerable <IWebElement> choices = null; IEnumerable <IWebElement> to_select = null; string[] values = null; for (int retry = 0; retry < 5; retry++) { choices = this.GetAllChoiceDivs(); to_select = from choice in choices where choice.GetAttribute("data-value") == v select choice; values = to_select.Select(x => x.Text).ToArray(); if (values.Length > 0) { break; } ShinyUtilities.ShinyWait(driver); } this.wait.Until(driver1 => to_select.First().Displayed); to_select.First().Click(); }
private void ReloadImage() { IWebElement img_elem = null; ShinyUtilities.ShinyWait(driver); wait.Until(d => img_elem = driver.FindElement(By.XPath(this.img_path))); img_str = img_elem.GetAttribute("src"); }
public double MoveSliderToValue(double target) { if (target < low) { target = low; } if (target > high) { target = high; } Actions builder = new Actions(this.driver); var grid = driver.FindElement(By.XPath(this.grid_path)); var width = grid.Size.Width; var old_x = width * (current - low) / (high - low); var new_x = width * (target - low) / (high - low); builder.MoveToElement(grid, (int)old_x, 0).ClickAndHold(); builder.MoveByOffset((int)(new_x - old_x), 0).Release().Build().Perform(); ShinyUtilities.ShinyWait(driver); this.current = Double.Parse(driver.FindElement(By.XPath(current_path)).GetAttribute("textContent")); return(this.current); }
public string EntrySetFromTo(double from, double to) { OpenTooltip(); if (from < low) { from = low; } if (from > to) { from = to; } var min = driver.FindElement(By.XPath(min_path)); min.Clear(); min.SendKeys(from.ToString()); if (to > high) { to = high; } if (to < from) { to = from; } var max = driver.FindElement(By.XPath(max_path)); max.Clear(); max.SendKeys(to.ToString()); driver.FindElement(By.XPath(submit_path)).Click(); wait.Until(d => GetValue(to_path) == to); wait.Until(d => GetValue(from_path) == from); this.to = to; this.from = from; ShinyUtilities.ShinyWait(driver); return(this.from.ToString() + "-" + this.to.ToString()); }
public IEnumerable <string> GetAllChoices() { // TODO(tthomas): Find a way to turn the retry logic into a function. IEnumerable <string> choices; int tries = 3; while (true) { try { var choices_divs = this.driver.FindElements(By.XPath(this.choices)); var choices_list = new List <string>(); for (var i = 0; i < choices_divs.Count(); i++) { choices_list.Add(choices_divs[i].GetAttribute("data-value")); } choices = choices_list.AsEnumerable(); break; } catch (OpenQA.Selenium.NoSuchElementException) { ShinyUtilities.ShinyWait(driver); if (--tries == 0) { throw; } } catch (OpenQA.Selenium.StaleElementReferenceException) { ShinyUtilities.ShinyWait(driver); if (--tries == 0) { throw; } } } return(choices); }
public double EntrySetTo(double to) { OpenTooltip(); if (to > high) { to = high; } if (to < from) { to = from; } var max = driver.FindElement(By.XPath(max_path)); max.Clear(); max.SendKeys(to.ToString()); driver.FindElement(By.XPath(submit_path)).Click(); wait.Until(d => GetValue(to_path) == to); this.to = to; ShinyUtilities.ShinyWait(driver); return(this.to); }
public double EntrySetFrom(double from) { OpenTooltip(); if (from < low) { from = low; } if (from > to) { from = to; } var min = driver.FindElement(By.XPath(min_path)); min.Clear(); min.SendKeys(from.ToString()); driver.FindElement(By.XPath(submit_path)).Click(); wait.Until(d => GetValue(from_path) == from); this.from = from; ShinyUtilities.ShinyWait(driver); return(this.from); }
public bool ToggleState() { driver.FindElement(By.Id(id)).Click(); ShinyUtilities.ShinyWait(driver); return(state = !state); }
public void ClickByName(string n) { driver.FindElement(By.XPath("//*[name()='svg' and @id='design_configurations_svg']/*[name()='g']/*[name()='g']/*[name()='text' and text()='" + n + "']/..")).Click(); ShinyUtilities.ShinyWait(driver); }