public void SeleniumAPI_Demo4()
        {
            _output.WriteLine("Step 01 : 启动浏览器并打开博客园首页。");
            IWebDriver driver = new FirefoxDriver();
            driver.Url = "http://www.cnblogs.com";

            _output.WriteLine("Step 02 : 寻找需要操作的页面元素。");
            var divText = driver.FindElement(By.Id("site_nav_top"));            
            var point = divText.Location;
            var width = int.Parse(divText.GetCssValue("width").Replace("px", string.Empty));
            
            _output.WriteLine("Step 03 : 选中文本信息。");
            var action = new Actions(driver);
            action
                .MoveByOffset(point.X, point.Y)         //移动鼠标到文本开头
                .ClickAndHold()                         //按下鼠标    
                .MoveByOffset(point.X + width, point.Y) //移动鼠标到文本结束
                .Release()                              //释放鼠标
                .Build()
                .Perform();

            System.Threading.Thread.Sleep(5000);
            _output.WriteLine("Step 04 : 关闭浏览器。");
            driver.Close();
        }
        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);
        }
예제 #3
0
        // Mark this test with TestMethod attribute, if need to check error
        // of mouse move actions in Selenium.
        public void TestGestures_SeleniumMouseMoveError()
        {
            Dictionary<string, object> offset;

            const int startX = 100;
            const int startY = 100;

            Actions action = new Actions(Driver);
            action.MoveToElement(vcPageObj.VirtualCanvas, startX, startY).Perform();

            for (int i = 0; i < 101; i++)
            {
                GoToUrl();

                action.Build();
                action.ClickAndHold();
                action.MoveByOffset(i, i);
                action.Release();
                action.MoveByOffset(-i, -i);
                action.Perform();

                offset = ExecuteScriptGetJson("return offset;");
                Console.WriteLine("Expected offset ({0}, {1}); Observed offset: ({2}, {3});", i, i, offset["xOffset"], offset["yOffset"]);
            }
        }
예제 #4
0
		public void DeleteModule(string moduleNumber)
		{
			Trace.WriteLine(BasePage.TraceLevelComposite + "Delete the Module:");

			SelectFromSettingsMenu(moduleNumber, DeleteOption);

			Actions builder = new Actions(_driver);
			builder.MoveByOffset(300,100).Build().Perform();

			WaitForConfirmationBox(60);
			ClickYesOnConfirmationBox();
		}
예제 #5
0
 public IMouseActions MoveByOffset(int offsetX, int offsetY)
 {
     actions.MoveByOffset(offsetX, offsetY);
     return(this);
 }
예제 #6
0
        private static List<string> GenerateTooltipMessages(IWebDriver driver, List<Point> graph,
            HighchartsPage page)
        {
            Actions action = new Actions(driver);

            action.MoveToElement(page.RootElement, 0, 0)
                .MoveByOffset(graph[0].X, graph[0].Y)
                .Build()
                .Perform();
            List<string> tooltip = new List<string>();
            for (int point = 1; point < graph.Count; point++)
            {
                for (int i = 0; i <= graph[point].X - graph[point - 1].X; i+=Step)
                {
                    action.MoveByOffset(Step, 0).Build().Perform();
                    if (tooltip.LastOrDefault() != page.TooltipElement.Text &&
                        page.TooltipElement.Text.Contains(HighchartsPage.EmployeeKeyword))
                    {
                        tooltip.Add(page.TooltipElement.Text);
                    }
                }
                action.MoveByOffset(0, graph[point].Y - graph[point - 1].Y)
                    .Build()
                    .Perform();
            }
            return tooltip;
        }
예제 #7
0
        public void moveTo(int x, int y)
        {
            int effectiveOffset = 0;
            int step = 1;
            int a = x > 0 ? step : -step;
            int b = y > 0 ? step : -step;

            while (effectiveOffset < Math.Abs(x))
            {
                var build = new Actions(Cons.driver);
                build.MoveByOffset(a, 0).ContextClick().Build().Perform();
                effectiveOffset += step;
            }
            effectiveOffset = 0;
            while (effectiveOffset < Math.Abs(y))
            {
                var build = new Actions(Cons.driver);
                build.MoveByOffset(0, b).ContextClick().Build().Perform();
                effectiveOffset += step;
            }
        }