I am trying to locate a dropdown menu button from the following website:
Inspect Element snippet of 'CRO Dashboard DropDown Menu'
My aim is to locate the dropdown button element and click it to open the menu to then continue other operations on it.
The following error occurs when trying to locate the dropdown menu button by id:
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"css selector","selector":"#dashboardSelectorLink"}
Referring to the image, from the highlighted part I tried to use various locators like finding element by id, css selector, class names, and even xpath but still the program could not locate it so that I can click the element.
Here is some of the code I tried:
dropdown = FindElementByCSS(dropdown, ".ms-crm-ImageStrip-Dropdown_Arrow");
dropdown = FindElementByXPath(dropdown, "//a[@id='dashboardSelectorLink']/span[2]/img");
dropdown = driver.FindElement(By.CssSelector("a[id=\"dashboardSelectorLink\"]"));
dropdown = FindElementByID(dropdown, "dashboardSelectorLink");
dropdown = FindElementByXPath(dropdown, "//cssclass[@id='dashboardSelectorLink']");
dropdown = FindElementByCSS(dropdown, "cssclass[id = 'dashboardSelectorLink']");
dropdown = FindElementByID(dropdown, "dashboardSelectorLink");
dropdown = FindElementByClass(dropdown, "cssclass[id= 'dashboardSelectorLink']");
dropdown = FindElementByID(dropdown, "dashboardSelectorContainer");
The variable 'dropdown' is of IWebElement type and I am using a chrome driver for Selenium C#.
For context, the code is in the following function:
public void EnterDashboardArea()
{
IWebElement navbtn = null;
IWebElement category = null;
IWebElement dropdown = null;
navbtn = FindElementByID(navbtn, "Tab1");
ClickElement(navbtn);
category = FindElementByID(category, "MNG");
ClickElement(category);
Thread.Sleep(5000); //pausing the program so the page fully loads and all elements appear
dropdown = driver.FindElement(By.CssSelector("img[class='ms-crm-ImageStrip-Dropdown_Arrow']"));
ClickElement(dropdown);
}
In the function EnterDashboardArea(), the web elements initially are set to none where they are then filled by the functions 'FindElementByX' as they return an element value.
The functions 'FindElementByX' are created by myself, one e.g. is:
public IWebElement FindElementByID(IWebElement ele, string id) {
ele = driver.FindElement(By.Id(id));
return ele;
}
I even tried installing the selenium chrome extension in order to locate the target exactly but still no success.
What can I do please? - Thanks