0
driver.FindElement(By.Id("diagnosisivd")).Click();

While running above code getting error:

"main" org.openqa.selenium.NoSuchElementException: no such element

As I have written correct id.

3
  • Have you written code to wait for the element to appear before this command?
    – Bhavani
    Jan 31, 2018 at 9:26
  • We don't know that it's a valid ID unless we can see the HTML code. Perhaps it's a valid ID, but the element is not a clickable element? When you say "Above code display error" you leave it up to us to guess what error is being reported. Share the error message. The more information you provide, the better the community can help you. Jan 31, 2018 at 15:27

2 Answers 2

3
  1. First correct your syntax error:

    driver.findElement(By.id("diagnosisivd")).click();

  2. If this is correct and still your are facing the same then try by adding some wait at some conditions.

    WebDriverWait wait = new WebDriverWait(driver, 15); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("diagnosisivd")));

  3. Try with different locator type XPath/CSSSelector-

    By.xpath : //*[@id='diagnosisivd']

0

Even if I don't know anything about it, what you can try is to run the test in debug mode and set a breakpoint on that instruction. If once you run it you wait some time before executing the instruction in the breakpoint and it works, then it's a matter of timing. Probably the element is not there yet when you try to click on it. Otherwise you can put an explicit wait for something like 5 seconds before that instruction and check if it works. If it works, remove the explicit wait and make the wait depending on the presence and clickability of that element.

Not the answer you're looking for? Browse other questions tagged or ask your own question.