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 11円 matching.

c32hedge
2,70920 silver badges39 bronze badges
asked May 14, 2019 at 12:32
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? Commented May 15, 2019 at 14:12
  • thats got resolved Commented 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 Commented 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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.