1

I am trying to click on a button on an application which is react based. It throws NoSuchElementException. I am very sure that the element name is correct . I tried with CSS, XPATH but nothing worked. Initially I thought I might be somehow using the wrong element . So to rule out this possibility I used selenium IDE and Katalon studio and did a click on that element to capture the correct XPATH or CSS. But, interestingly selenium or Katalon both did not capture the element. Instead they both showed that I click on this “agentx-app” option which is not a button or any clickable item.

Button element:

<button part="button" id="" class="md-button md-button--32" tabindex="0" aria-pressed="false" aria-label="Unavailable" aria-labelledby="" aria-expanded="false" aria-haspopup="false" type="button" role="button">
  <span class="md-button__children">
    <slot name="text"></slot>
   <slot></slot>
      </span>
 </button>

HTML:

Please see the image . Added image as I could not copy the HTML content.

None of the below worked:

public static void clickElement(String type, String tag) {
    if (type.equals("name")) {
        driver.findElement(By.name(tag)).click();
    } else if (type.equals("tagName")) {
        driver.findElement(By.tagName(tag)).click();
    } else if (type.equals("id")) {
        driver.findElement(By.id(tag)).click();
    } else if (type.equals("xpath")) {
        driver.findElement(By.xpath(tag)).click();
    } else if (type.equals("css")) {
        driver.findElement(By.cssSelector(tag)).click();
    } else if (type.equals("linkText")) {
        driver.findElement(By.linkText(tag)).click();
    } else if (type.equals("classname")) {
        driver.findElement(By.className(tag)).click();
    }
}

Calling click button:

public void clickButton() {
        UtilWebDriver.waitForPageToLoad("xpath", "//*[@id="menu-overlay"]/md-tooltip/md-button//button");
        UtilWebDriver.clickElement("xpath", "//*[@id="menu-overlay"]/md-tooltip/md-button//button");
        
    }

I simply am not able to interact with the buttons. And there does not appear to be any iframe as well . Any idea. 

enter image description here

AmKu
  • 23
  • 4
  • What are the methods you actually used to try? Did you inclide a wait for element present before attempting findElement? – DMart Dec 11 '20 at 17:57
  • Visit the site manually. Once the button is clickable right-click and choose "inspect". Include that markup in your post. Right now you have some markup there that is meant to be a placeholder for content that will be added later. (It's empty as posted in your question.) – pcalkins Dec 11 '20 at 18:09
  • Just added the image which contains the markup . I do wait for the page to load before attempting to click anywhere. The problems is that I cannot simply find that element. something like this:wait.until(ExpectedConditions.or( ExpectedConditions.visibilityOfElementLocated(By.name(tag)))); – AmKu Dec 11 '20 at 18:12
  • Please add the line where you call the `clickElement` function. – Jortega Dec 11 '20 at 18:59
  • Here. It is tried with CSS as well .public void clickButton() { UtilWebDriver.waitForPageToLoad("xpath", "//*[@id="menu-overlay"]/md-tooltip/md-button//button"); UtilWebDriver.clickElement("xpath", ""//*[@id="menu-overlay"]/md-tooltip/md-button//button""); } – AmKu Dec 11 '20 at 19:13

0 Answers0