3

I have one more issue with Selenium webdriver, I am writing a test, where I need draw a polygon on the map (map is based on Esri API). I have successfully managed to zoom in, but couldn't find any examples, how to draw a polygon on the map or how to put polygon vertex using x,y coordinate from the map.

Here is my code part, I cannot show url, it's private:

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 version 67.0.3396.99, 64 bit Visual C# 2017 Webdriver version 3.13.1.0

Hope, you have some ideas! Tnx.

Aad Ali
  • 61
  • 5

1 Answers1

2

I have found a solution, probably, someone will need it, too. In my task, I have managed to draw a polygon by 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);
Aad Ali
  • 61
  • 5
  • May I know what is map here in the code? How do you select the XPath of the map? Is this any random point in the map?: vertex1.MoveToElement(map).MoveByOffset(100, 100).Click();? – arpita biswas Apr 01 '22 at 05:58
  • And what is karte in the code: vertex4.MoveToElement(karte).MoveByOffset(100, 10).DoubleClick(); – arpita biswas Apr 01 '22 at 06:08