0

I'm writing a test(using selenium) to verify that after a i right click on a particular part of our website, it should show the standard context menu (copy, past, reload, saveAs etc) and not our created context menu.

I need to find a way to check the items on the context menu after the right click, any ideas?

Heres where i am so far...

  private IWebDriver driver = null;
    private WebDriverWait wait = null;
    private Actions action;

    [TestInitialize()]
    public void Initialize()
    {
        driver = new ChromeDriver();
        driver.Navigate().GoToUrl("http://localhost/testwebportal");
        wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
        action= new Actions(driver);
    }

    [TestMethod]

    public void Right_click_brochure_while_zoomed_in_ID_8_2()
    {
        // click brochure
        var clickFirstProduct =    driver.FindElement(By.CssSelector("div.MetaSearchBrochureTile:nth-child(1) > div:nth-child(1) > img:nth-child(2)"));
        clickFirstProduct.Click();
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1500));

        // zoom in
        var brochurePage = driver.FindElement(By.CssSelector(".p1"));
        brochurePage.Click();

        action.ContextClick(brochurePage);

        // code to check if context menu is not my created right click menu browser,               
        // by looking at the menu items after the right click.


        action.Perform();

    }

Ray

user3105158
  • 61
  • 3
  • 15
  • Can you give a little bit more context to your question? What language are you using to drive your selenium tests? What particular problem are you having with your non-domain specific selenium code? I.e. the right click part? – craastad Mar 18 '14 at 09:37
  • All in C#. I'm able to get the menu after a right click. but i now what to see if that menu, is the default menu. (standard menu) by checking the items on that menu. And not showing our created menu. Thanks. – user3105158 Mar 18 '14 at 09:56

2 Answers2

0

If you are looking for the machinary to drive a selenium right click, check out how to do a right click in selenium or how to simulate a right click with code in selenium.

Community
  • 1
  • 1
craastad
  • 6,222
  • 5
  • 32
  • 46
0

I hope this helps. If I have miss understood your question please let me know. Since you did not give me the HTML structure I have made many assumptions.

ContextOption is an array of string with contains the options expected in the context menu. What I am doing is comparing the options expected with the optionsdisplayed in the context menu by text. This will return false if any one them is mismatched, less than what you expected or more than what you expected

Please remember to replace the code with proper element locaters.

    var actions = new Actions(driver);

    WebElement webElement = driver.FindElement(By.XPath("")));
    actions.ContextClick(webElement).Perform();
    int numberOfOptionPresent = 0;
    foreach (var option in ContextOption)
    {
        IWebElement contextOptions = driver.FindElement(By.XPath(""));
        ReadOnlyCollection<IWebElement> totalContextOption = contextOptions.FindElements(By.TagName("li"));
        for (int c = 1; c <= totalContextOption.Count; c++)
        {
            string contextText = driver.FindElement(By.XPath("li[" + c + "]")).Text;

            if (contextText == option)
            {
                if (contextText != "")
                {
                    numberOfOptionPresent++;
                }
                break;
            }
            if (totalContextOption.Count == c)
            {
                 return false;
            }
        }
        if (numberOfOptionPresent == ContextOption.Count())
        {
            return true;
        }
        return false;
    }
craastad
  • 6,222
  • 5
  • 32
  • 46
Anand S
  • 760
  • 5
  • 13
  • 28