0

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?

3
  • Can you just share the site? Commented Jun 22, 2016 at 4:37
  • When you watch the script execute, do you see the submenus opening? If the wait suggested in Guy's answer below isn't working, then you probably aren't hovering the right element or something. Hard to tell without seeing the site. Commented Jun 23, 2016 at 14:59
  • Hey @JeffC, it is working. Just updated the comment. Commented Jun 23, 2016 at 20:18

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I got an error. The driver timed out after 5 seconds. Do you think it has something to do with the Xpath?
@AmberO Is there something covering the dropdown?
your answer worked. I think it was taking more time to load. Increased the time.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.