1

In my case, I choose a file and I open the drop-down menu.

In the drop-down menu are three actions:

  1. Add tag
  2. Remove tag
  3. Lock document

I use "Lock document" action and after that if I choose the same file and open the menu, the action Lock document will disappear.

Questions:

  1. how to determine the count of actions in the menu?
  2. how to verify if action "Lock document" disappeared ?
1
  • Is the dropdown a <select> element with dropdown menu as <option> elements or a custom element?
    – Zeeshan S.
    May 1, 2017 at 10:41

2 Answers 2

1

I'm a Java developer, but I'll give C# a try as well:

  1. how to determine the count of actions in the menu?
IWebElement elem = driver.FindElement(locator);
SelectElement selectList = new SelectElement(elem);
IList options = selectList.Options;
int count = options.Count;
  1. how to verify if action "Lock document" disappeared ?
bool containsLockDoc = false;
foreach (IWebElement option in options)
{
    string actual = option.Text();
    string expected = "Lock document";
    containsLockDoc = actual.Equals(expected);
    if(containsLockDoc) {
        break; // Lock Document exists in the dropdown options list
    }
}
2
  • Can you help me with this error ?
    – Majkl
    May 4, 2017 at 5:56
  • 1
    It works. I changed this line: containsLockDoc = actual.Contains(expected);
    – Majkl
    May 4, 2017 at 13:16
0

Here is the code for menu:

<ul class="dropdown-menu" role="menu">
<li role="presentation">
<li role="presentation">
<li class="mlck divider" role="presentation"/>
<li class="mlck" role="presentation">
<li class="divider" role="presentation"/>
<li role="presentation">
<li class="divider" role="presentation"/>
<li role="presentation">
<a onclick="tagl(); return false;" tabindex="6" role="menuitemradio">Lock document</a>
</li>
<li role="presentation">
<li class="mlck divider" role="presentation"/>
<li class="mlck" role="presentation">
</ul>

I used this code:

IWebElement elem = driver.FindElement(By.XPath(apath));
            SelectElement selectList = new SelectElement(elem);
            IList<IWebElement> options = selectList.Options;

            bool containsLockDoc = false;
            foreach (IWebElement option in options)
            {
                string actual = option.Text;
                string expected = "Lock document";
                containsLockDoc = actual.Equals(expected);
                if (containsLockDoc)
                {
                    break; // Lock Document exists in the dropdown options list
                }
            }

And I got error:

OpenQA.Selenium.Support.UI.UnexpectedTagNameException: Element should have been select but was ul

1
  • Can anybody help me with this error ?
    – Majkl
    May 4, 2017 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.