0

I tried to click on an element using the code below but it is throwing Exception: No Such Element Selections

WebElement clear=driver.findElement(By.xpath(PageUtility.OPEN_LOCATION_POPUP_XPATH));        
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", clear);

and while finding xpath it gave the 1\1 matching.

3
  • You've named the element clear. I'm assuming it's clearing text or something? Does it only appear if there's text present? Or is it always present? Because if you need to perform an action to show the element, maybe that action isn't performed?
    – Camarde
    May 15, 2019 at 14:12
  • thats got resolved
    – jay
    May 16, 2019 at 12:14
  • If you are dealing with a popup you may have to switch to the pop. guru99.com/alert-popup-handling-selenium.html
    – Syrus
    Jun 14, 2019 at 4:44

1 Answer 1

0

If you're 100% sure that the XPath selector is correct the problem can have at least 2 possible causes:

  1. Element hasn't been fully loaded yet, it might appear later than document.readyState reports complete as it might be added later as the result of an AJAX call execution. If this is the case - consider using an Explicit Wait to ensure that the element is there prior to attempting interacting with it.

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath(PageUtility.OPEN_LOCATION_POPUP_XPATH)));
    
  2. The element might reside in an iframe, if this is the case you will need to switch to the relevant context


The element can be hidden in the Shadow DOM, if it's so - you won't be able to locate it using findElement() function and will need to consider another strategy of element location.

2
  • I have added Explicit wait but getting timeoutException, any other way to click an element
    – jay
    May 14, 2019 at 13:35
  • anyhelp is highly appreciated
    – jay
    May 14, 2019 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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