-2

I am trying to find the element using Dynamic x path but my code is not working for the element

<a href="/corporate-checkups/our-corporate-services.html" class="has-submenu" id="sm-15547263985364824-1" aria-haspopup="true" aria-controls="sm-15547263985364824-2" aria-expanded="false"><span class="sub-arrow">+</span>Our Services</a>

Want to select sub-menu by using Action class but here i am unable to locate the element

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • 2
    Please provide your html code and error stack trace – Dhru 'soni Apr 08 '19 at 12:46
  • @SurajsinghAutoQA What exactly do you mean by _...select sub-menu by using Action class..._? `select` -> `click()`?? `sub-menu` = `+`??? Is `Action` class mandatory???? – DebanjanB Apr 08 '19 at 13:14

2 Answers2

0

To click() on the sub-menu you can use either of the following Locator Strategies (Java Solution):

  • cssSelector:

    driver.findElement(By.cssSelector("a.has-submenu[href='/corporate-checkups/our-corporate-services.html']>span.sub-arrow")).click();
    
  • xpath:

    driver.findElement(By.xpath("//a[@class='has-submenu' and @href='/corporate-checkups/our-corporate-services.html']/span[@class='sub-arrow']")).click();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

Basically your locator its a link so you have to very simple options :

driver.findElement(By.partialLinkText(“Element LINKTEXT”));

driver.findElement(By.LinkText(“Element LINKTEXT”));

Choose which one you think works better for you.

teddym6
  • 88
  • 9