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.
1 Answer 1
If you're 100% sure that the XPath selector is correct the problem can have at least 2 possible causes:
Element hasn't been fully loaded yet, it might appear later than
document.readyState
reportscomplete
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)));
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.
-
I have added Explicit wait but getting timeoutException, any other way to click an elementjay– jay2019年05月14日 13:35:03 +00:00Commented May 14, 2019 at 13:35
-
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?