0

I am trying click a menu icon which has the following html code

<a href="#" class="ctm-icon-link" onclick="show_menu('doc_107094', 1); return false;"><i class="icon-left-space icon-chevron-sign-down">&nbsp;</i></a>

doc_number -Number will change each time My code to click the icon menu

FindElement(By.ClassName("ctm-icon-link"));
FindElement(By.XPath("//a[@href='#']@onclick"));
FindElement(By.XPath("//a[@href="#"]@class"));
Guy
  • 46,488
  • 10
  • 44
  • 88
jesintha roselin
  • 171
  • 1
  • 15

1 Answers1

0

To locate the element with respect to the onclick event you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • XPath 1:

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@class='ctm-icon-link' and starts-with(@onclick, 'show_menu')]")));
    
  • XPath 2:

    IWebElement element = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//a[@class='ctm-icon-link' and starts-with(@onclick, 'show_menu')]/i")));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352