0

I try doing a right-click on a position that is calculated based on the input. The input and the evaluation work already. But I don't know how to do the right-click at the found position. Does anyone know how this works in my use case? Here is the code:

public class MapAnalyser {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:/uti/PC/chromedriver/chromedriver.exe");
        final ChromeDriver driver = new ChromeDriver();
        driver.get("https://map.geo.admin.ch/");
        final WebElement searchBar = driver.findElementByCssSelector("#search-container > div > form > span.ga-search-input-container > input");
        searchBar.sendKeys("199340 825798");

        final Actions action = new Actions(driver);
        // The container match with the expected element
        final List<WebElement> boxs = driver.findElementsByXPath("/html/body/div[5]/div[5]/div[2]/div");

        System.out.println(boxs.size());

       // How to perform the right click on the search position?
       // Find the crosshairs and right click at this position. Right click does not work
       // action.contextClick(driver.findElementsByXPath("don’t now how]").get(0)).build().perform();
       // if the right click is performed the correct values are provided

        new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(boxs.get(0)))).clickAndHold(boxs.get(0)).build().perform();

        for (final WebElement element : boxs) {
            System.out.println("Infos:" + element.getText());
        }
    }
}

crosshairs is already shown in the map

Expected Result, if the automated right click work fine

Bennet
  • 1
  • 1
  • Does this help [link]https://stackoverflow.com/questions/7914684/trigger-right-click-using-pure-javascript - not the accepted answer but the 2018 answer from @jmiserez – A Haworth Feb 06 '21 at 21:35
  • Thanks for the link! The main problem is to figure out the correct xpath for the found position in the map (get the corresponding WebElement). Maybe this element is dynamic generated and I don't know how to access it. – Bennet Feb 10 '21 at 18:54

0 Answers0