Search code examples
javaseleniumxpathautomationkrypton

Cannot click an icon within a div. Selenium Java


code cannot find this icon wherein i have to click it i just notice that it is within a div. here is my sample code:

findLink(By.xpath("//div[@aria-label='Dashlet Actions' and contains(@ng-click,'updateActionMenu')]")).click

please see image for further information

enter image description here


Solution

  • To click on the desired element you can use the following solution:

    • css:

      findLink(By.css("button.btn.btn-link[aria-label='Dashlet Actions']")).click
      
    • XPath:

      findLink(By.xpath("//button[@class='btn btn-link' and @aria-label='Dashlet Actions']")).click
      

    Note: The element is an Angular element so you have to induce ExplicitWait for the desired element to be clickable