2

Selenium webdriver 还有一个问题,我正在编写一个测试,我需要在地图上绘制一个多边形(地图基于 Esri API)。我已成功放大,但找不到任何示例,如何在地图上绘制多边形或如何使用地图中的 x,y 坐标放置多边形顶点。

这是我的代码部分,我无法显示 url,它是私有的:

namespace MK_edit

    {
        class Program
        {
            static void Main(string[] args)
            {
                IWebDriver driver = new ChromeDriver(@"C:\Users\ProjectLibre");
                driver.Url = "----";
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60); 
                driver.Manage().Window.Maximize();

//close popup               
                driver.FindElement(By.CssSelector("div.whatsnew-content"));
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
                driver.FindElement(By.CssSelector("button.btn.btn-success")).Click(); 
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);

 //open element for editing              
                var lab = driver.FindElement(By.CssSelector("a[title=\"-\"]"));
                var icon = driver.FindElement(By.CssSelector("span.glyphicon.glyphicon-edit"));
                var loadingBackgrop = driver.FindElement(By.ClassName("overlay")); 

                IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
                js.ExecuteScript("arguments[0].style='display: none;'", icon); 

                var wait= new WebDriverWait(driver, new TimeSpan(0, 0, 60));
                WaitForNotVisible(loadingBackgrop, driver);
                wait.Until(ExpectedConditions.ElementToBeClickable(lab)); 
                lab.Click();
//choose layer form the list    
                var layer_list = driver.FindElement(By.CssSelector("#edit-layerlist-holder .combobox-wrapper .selectize-input.items"));
                WaitForNotVisible(loadingBackgrop, driver);
                wait.Until(ExpectedConditions.ElementToBeClickable(layer_list));
                layer_list.Click();

                var forest = driver.FindElement(By.CssSelector("body > div:nth-child(12) > div > div:nth-child(15) > div:nth-child(21)"));
                forest.Click();
//zoom in map x,y    
                var map = driver.FindElement(By.CssSelector("#map_gc"));
                map.Click();
                js.ExecuteScript("ng.geometryTools.zoomToXY(***177, ***289)"); 
                var edit = driver.FindElement(By.CssSelector("#edit-drawbtn"));
                edit.Click(); }

Chrome 版本 67.0.3396.99,64 位 Visual C# 2017 Webdriver 版本 3.13.1.0

希望,你有一些想法!肿瘤坏死因子。

4

1 回答 1

1

我找到了一个解决方案,可能有人也需要它。在我的任务中,我设法通过 Actions 绘制了一个多边形:

// polygon vertex
            Actions vertex1 = new Actions(driver);
            vertex1.MoveToElement(map).MoveByOffset(100, 100).Click();
            IAction clickNextPoint = vertex1.Build();
            clickNextPoint.Perform();

            Actions vertex2 = new Actions(driver);
            vertex2.MoveToElement(map).MoveByOffset(10,100).Click();
            IAction clickNextPoint2 = vertex2.Build();
            clickNextPoint2.Perform();

            Actions vertex3 = new Actions(driver);
            vertex3.MoveToElement(map).MoveByOffset(10, 10).Click();
            IAction clickNextPoint3 = vertex3.Build();
            clickNextPoint3.Perform();

            Actions vertex4 = new Actions(driver);
            vertex4.MoveToElement(karte).MoveByOffset(100, 10).DoubleClick();
            System.Threading.Thread.Sleep(3000);
于 2018-08-13T13:02:32.703 回答