Amber O
Amber O

Reputation: 67

Access submenu in Selenium using c#

Hi I am trying to access a submenu in selenium using c#. On my the website that I am testing the mouseover to the menu opens another submenu1,mouseover to submenu1 options open submenu2. I want to click on one of the submenu2 options. I tried to run below, everytime it throws an error of element not visible on custonboarding.Click();

Actions builder = new Actions(driver);

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));

var hoverover = driver.FindElement(By.XPath("menu1"));
builder.MoveToElement(hoverover).Build().Perform();

var hoverover1 = driver.FindElement(By.XPath("submenu1));
builder.MoveToElement(hoverover1).Build().Perform();

var custonboarding = driver.FindElement(By.XPath("submenu2"));
custonboarding.Click();

Can someone help me out here?

Upvotes: 0

Views: 599

Answers (1)

Guy
Guy

Reputation: 51009

It might take some time for the element to fully load. You can use explicit wait and ExpectedConditions to wait for the element to be visible

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
IWebElement custonboarding = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("submenu2")));
custonboarding.Click();

This will wait up to 5 seconds for the element to be visible.

Upvotes: 1

Related Questions