本文整理汇总了C#中OpenQA.Selenium.Interactions.Actions类的典型用法代码示例。如果您正苦于以下问题:C# Actions类的具体用法?C# Actions怎么用?C# Actions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Actions类属于OpenQA.Selenium.Interactions命名空间,在下文中一共展示了Actions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InPutSearchStringAndPressEnter
public void InPutSearchStringAndPressEnter(string text)
{
Actions action = new Actions(TestRunner.Driver);
action.DoubleClick(SearchInput()).Build().Perform();
SearchInput().Clear();
SearchInput().SendKeys(text + OpenQA.Selenium.Keys.Enter);
}
示例2: ActivateWorkload
/// <summary>
///
/// </summary>
/// <returns></returns>
public DashboardPage ActivateWorkload()
{
bool isActivateButtonDisplayed = this.WaitForElement("XPATH", (string)objectRepository.ObjectRepositoryTable["ActivateButton"]);
if (isActivateButtonDisplayed)
{
activateButtonControl = this.FindControlByXPath((string)objectRepository.ObjectRepositoryTable["ActivateButton"]);
Actions action = new Actions(this.Browser.Driver);
action.MoveToElement(activateButtonControl).DoubleClick().Perform();
ImplicitlyWait(5000);
bool isActivateTrialButtonDisplayed = this.WaitForElement("XPATH", (string)objectRepository.ObjectRepositoryTable["ActivateTrialButton"]);
if (isActivateTrialButtonDisplayed)
{
IWebElement activateTrailButtonControl = this.FindControlByXPath((string)objectRepository.ObjectRepositoryTable["ActivateTrialButton"]);
action.MoveToElement(activateTrailButtonControl).DoubleClick().Perform();
ImplicitlyWait(10000);
return new DashboardPage(this.Browser);
}
else
{
throw new Exception("Activate Trial Button not found");
}
}
else
{
throw new Exception("Activate button not found");
}
}
示例3: ShouldAllowSelectingMultipleItems
public void ShouldAllowSelectingMultipleItems()
{
driver.Url = selectableItemsPage;
IWebElement reportingElement = driver.FindElement(By.Id("infodiv"));
Assert.AreEqual("no info", reportingElement.Text);
ReadOnlyCollection<IWebElement> listItems = driver.FindElements(By.TagName("li"));
Actions actionBuider = new Actions(driver);
IAction selectThreeItems = actionBuider.KeyDown(Keys.Control)
.Click(listItems[1])
.Click(listItems[3])
.Click(listItems[5])
.KeyUp(Keys.Control).Build();
selectThreeItems.Perform();
Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text);
// Now click on another element, make sure that's the only one selected.
actionBuider.Click(listItems[6]).Build().Perform();
Assert.AreEqual("#item7", reportingElement.Text);
}
示例4: Hover
public void Hover(Element element)
{
var sequenceBuilder = new Actions(selenium);
var actionSequenceBuilder = sequenceBuilder.MoveToElement((IWebElement) element.Native);
var action = actionSequenceBuilder.Build();
action.Perform();
}
示例5: Main
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.integrationqa.com/");
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement menu = driver.FindElement(By.Id("hs_menu_wrapper_module_13970568219884"));
Actions builder = new Actions(driver);
builder.MoveToElement(menu).Build().Perform();
IList<IWebElement> menuItemsList = menu.FindElements(By.ClassName("hs-menu-item"));
String[] menuItems = new String[menuItemsList.Count];
int i = 0;
foreach (IWebElement menuItem in menuItemsList)
{
menuItems[i++] = menuItem.Text;
}
//Arrange all the list items in alphabetical order
IEnumerable<String> orderedMenuList = menuItems.OrderBy(lv_menu => lv_menu).ToList();
//Display the ordered list
foreach (var menuItem in orderedMenuList)
{
if (menuItem.Length > 0)
Console.WriteLine(menuItem);
}
Console.ReadKey();
}
示例6: Main
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.seleniummaster.com/");
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
IWebElement menu = driver.FindElement(By.Id("menubar"));
Actions builder = new Actions(driver);
builder.MoveToElement(menu).Build().Perform();
IList<IWebElement> menuItemsList = menu.FindElements(By.Id("menu"));
char[] delim = { '\r', '\n' };
String[] menuList = menuItemsList[0].Text.Split(delim);
//Query to orderby all the list items
IEnumerable<string> orderedMenuList = menuList.OrderBy(lv_menu => lv_menu).ToList();
//Display the ordered list
foreach (string menuItem in orderedMenuList)
{
if (menuItem.Length > 0)
Console.WriteLine(menuItem);
}
Console.ReadKey();
}
示例7: Launch
internal void Launch(bool mobile, string url = "https://www.bing.com/") {
Quit();
_viewModel.ResetProfileCommand.RaiseCanExecuteChanged();
ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("user-data-dir=" + App.Folder + "profile");
if (mobile)
options.EnableMobileEmulation("Google Nexus 5");
try {
_driver = new ChromeDriver(service, options);
_driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
_builder = new Actions(_driver);
LogUpdate("Launching Chrome " + (mobile ? "Mobile" : "Desktop"), Colors.CadetBlue);
if (url != null)
_driver.Navigate().GoToUrl(url);
}
catch (Exception ex) {
LogUpdate("Error Launching Chrome " + (mobile ? "Mobile" : "Desktop") + "\r\n" + ex.Message, Colors.Red);
service.Dispose();
}
}
示例8: ShouldAllowSelectingMultipleItems
public void ShouldAllowSelectingMultipleItems()
{
if (!IsNativeEventsEnabled || (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Linux)))
{
Assert.Ignore("Skipping ShouldAllowSelectingMultipleItems: Only works with native events on Linux.");
}
driver.Url = selectableItemsPage;
IWebElement reportingElement = driver.FindElement(By.Id("infodiv"));
Assert.AreEqual("no info", reportingElement.Text);
ReadOnlyCollection<IWebElement> listItems = driver.FindElements(By.TagName("li"));
Actions actionBuider = new Actions(driver);
IAction selectThreeItems = actionBuider.KeyDown(Keys.Control)
.Click(listItems[1])
.Click(listItems[3])
.Click(listItems[5])
.KeyUp(Keys.Control).Build();
selectThreeItems.Perform();
Assert.AreEqual("#item2 #item4 #item6", reportingElement.Text);
// Now click on another element, make sure that's the only one selected.
actionBuider.Click(listItems[6]).Build().Perform();
Assert.AreEqual("#item7", reportingElement.Text);
}
示例9: ShouldAllowClickingOnFormElements
public void ShouldAllowClickingOnFormElements()
{
if (!IsNativeEventsEnabled || (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Linux)))
{
Assert.Ignore("Skipping ShouldAllowClickingOnFormElements: Only works with native events on Linux.");
}
driver.Url = formSelectionPage;
ReadOnlyCollection<IWebElement> options = driver.FindElements(By.TagName("option"));
Actions actionBuider = new Actions(driver);
IAction selectThreeOptions = actionBuider.Click(options[1])
.KeyDown(Keys.Shift)
.Click(options[2])
.Click(options[3])
.KeyUp(Keys.Shift).Build();
selectThreeOptions.Perform();
IWebElement showButton = driver.FindElement(By.Name("showselected"));
showButton.Click();
IWebElement resultElement = driver.FindElement(By.Id("result"));
Assert.AreEqual("roquefort parmigiano cheddar", resultElement.Text, "Should have picked the last three options.");
}
示例10: MaxZoom
//an boundary constraint (to prevent the user from observing the future and the past(e.g. before 13.7Ga BC) )
public void MaxZoom(double lt, double rt, int zoom)
{
IWebElement buttonZoomOut = Driver.FindElement(By.Id("buttonZoomOut"));
Actions actions = new Actions(Driver);
(Driver as IJavaScriptExecutor).ExecuteScript("$(\"#axis\").axis(\"setRange\"," + lt + "," + rt + ");");
actions.Build();
actions.MoveToElement(buttonZoomOut, 0, 0);
for (int k = 0; k < zoom; k++)
{
actions.Click();
}
actions.Release();
actions.Perform();
var afterZoom = (Driver as IJavaScriptExecutor).
ExecuteScript("return $(\"#axis\").axis(\"getRange\");");
var afterzooml = Convert.ToDouble((afterZoom as Dictionary<string, object>)["left"]);
var afterzoomr = Convert.ToDouble((afterZoom as Dictionary<string, object>)["right"]);
Assert.IsTrue(afterzooml >= -13700000000.0);
Assert.IsTrue(afterzoomr <= 0.0);
}
示例11: SetUpForFindElementsAndCreateActionsClass
public void SetUpForFindElementsAndCreateActionsClass()
{
this.textBox = this.MainWindow.FindElement(By.Id("TextBox1"));
this.button = this.MainWindow.FindElement(By.Id("SetTextButton"));
this.action = new Actions(this.Driver);
}
示例12: TheXTest
public void TheXTest()
{
driver = new FirefoxDriver();
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
Login u = new Login(driver);
string login1 = "guest";
u.get().login(login1, login1).click();//вход на сайт
driver.FindElement(By.Id("sovzond_widget_SimpleButton_104")).Click();
Thread.Sleep(5000);
IWebElement element = driver.FindElement(By.Id("sovzond_widget_SimpleButton_0"));
var builder = new Actions(driver);
builder.Click(element).Perform();
IList<IWebElement> el = driver.FindElements(By.ClassName("svzLayerManagerItem"));
for (int n = 0; n < el.Count; n++)
{
if (el[0].Text != "Google") Assert.Fail("не найден Google");
if (el[4].Text != "Росреестр") Assert.Fail("не найден Росреестр");
if (el[5].Text != "OpenStreetMap") Assert.Fail("не найден OpenStreetMap");
if (el[6].Text != "Топооснова") Assert.Fail("не найден Топооснова");
}
IWebElement element1 = driver.FindElement(By.Id("dijit_form_RadioButton_3"));
builder.Click(element1).Perform();
Thread.Sleep(5000);
string h= (string)js.ExecuteScript("return window.portal.stdmap.map.baseLayer.div.id.toString()");
}
示例13: ShouldAllowUsersToHoverOverElements
public void ShouldAllowUsersToHoverOverElements()
{
driver.Url = javascriptPage;
IWebElement element = driver.FindElement(By.Id("menu1"));
if (!Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
{
Assert.Ignore("Skipping test: Simulating hover needs native events");
}
IHasInputDevices inputDevicesDriver = driver as IHasInputDevices;
if (inputDevicesDriver == null)
{
return;
}
IWebElement item = driver.FindElement(By.Id("item1"));
Assert.AreEqual("", item.Text);
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.background = 'green'", element);
//element.Hover();
Actions actionBuilder = new Actions(driver);
actionBuilder.MoveToElement(element).Perform();
item = driver.FindElement(By.Id("item1"));
Assert.AreEqual("Item 1", item.Text);
}
示例14: MoveToFooter
protected void MoveToFooter(IWebElement footer)
{
Actions actions = new Actions(chrome);
actions.MoveToElement(footer);
actions.Perform();
Thread.Sleep(1000);
}
示例15: TestHtml5CanvasDrawing
public void TestHtml5CanvasDrawing()
{
try
{
driver.Navigate().GoToUrl("http://dl.dropbox.com/u/55228056/html5canvasdraw.html");
//Get the HTML5 Canvas Element
IWebElement canvas = driver.FindElement(By.Id("imageTemp"));
//Select the Pencil Tool
SelectElement drawtool = new SelectElement(driver.FindElement(By.Id("dtool")));
drawtool.SelectByText("Pencil");
//Create a Action Chain for Draw a shape on Canvas
Actions builder = new Actions(driver);
builder.ClickAndHold(canvas).MoveByOffset(10, 50).
MoveByOffset(50, 10).
MoveByOffset(-10, -50).
MoveByOffset(-50, -10).Release().Perform();
//Get a screenshot of Canvas element after Drawing and compare it to the base version
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
string screenshot = ss.AsBase64EncodedString;
byte[] screenshotAsByteArray = ss.AsByteArray;
ss.SaveAsFile(@"c:\tmp\post.png", ImageFormat.Png);
}
catch (Exception e)
{
Assert.Fail("Test Failed due to exception '" + e.Message + "'");
}
}