CRUZE
CRUZE

Reputation: 57

wait.until(ExpectedConditions.elementToBeClickable) is not waiting for the defined time

Using Using Selenium WebDriver with Java and I want to click on an element that is present on the page and is visible, but is grayed out, i.e., element is present on the page but the same is not intractable.

So, I am using ExplicitWebDriverWait to wait until that element is clickable and for that I am using below line of code. But the same is not working. Driver is not waiting for the element to become intractable. It is throwing exception, "is not clickable at point (415, 765). Other element would receive the click:".

Now,if I am using static wait instead of this Explicit Waint, I am able to click on the element.

Code which I have written:

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@name='mobile']")));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@name='mobile']")));
newNum.click();

Script Log:

Trying to locate: By.xpath: //*[@name='mobile']
Located element:By.xpath: //*[@name='mobile']
Trying to locate: By.xpath: //*[@name='mobile']
Located element:By.xpath: //*[@name='mobile']
Trying to locate: By.xpath: //*[@name='mobile']
Located element:By.xpath: //*[@name='mobile']
Trying to click on:[[ChromeDriver: chrome on XP (7686dd92e2bb577696qa2e1aa13effd6)] -> xpath: //*[@name='mobile']]
Exception occured:org.openqa.selenium.WebDriverException: unknown error: Element <input id="abc-radiobox-2032-inputEl" data-ref="inputEl" type="text" role="combobox" size="1" name="mobile" placeholder="- select option -" readonly="readonly" class="dummyclass" autocomplete="off" componentid="gwc-combobox-2032"> is not clickable at point (415, 765). Other element would receive the click: <div class="anotherclass" role="status" id="loadmask-1985" tabindex="0" componentid="loadmask-1985" style="">...</div>
  (Session info: chrome=71.0.3578.98)
  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e1234de03a32ff6c197e),platform=Windows NT 10.0.10586 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds

Upvotes: 0

Views: 3321

Answers (2)

Anuj Jain
Anuj Jain

Reputation: 11

According to the error you are getting:

Exception: is not clickable at point (415, 765). Other element would receive the click:

Seems like driver is not able to even find the particular element, so its not waiting until it becomes clickable. Mostly whenever this type of error occurs, we can use JavaScript Clicks instead of using wait or any other types of clicks.

Try the below code: make sure element locator's value should be good enough to locate the element uniquely:

WebElement element = driver.findElement(By.xpath("//*[@name='mobile']")); JavascriptExecutor Js = (JavascriptExecutor)driver; Js.executeScript("arguments[0].clicks();", element)

This code always works for me. Sometimes I need to insert scrollIntoView() method to scroll the page to the element to perform action on it.

Upvotes: 1

Sowmiya .v
Sowmiya .v

Reputation: 31

You should wait, until the element is visible. And then need to check whether element is in enable state(clickable state) or not. After that only, you have to perform the click operation.

Steps

1.Create Firefox browser session

2.Navigate to the page as per you requirement

3.Wait, until the web element (//*[@name='mobile']) is visible [wait for approximately 15 seconds]

[What is web element ? Ans : Whatever the action you are going to perform with this element. This element may be a button , link, icon, text field, etc..]

4.Now check the element, it is in clickable state(enable state) or not

5.If it is in clickable state(enable state), then perform the click operation.

public void test_01_ButtonClick()
{
WebDriver driver = new FirefoxDriver();
driver.navigate().to("www.hlo.com");            

//Here will check element is visible or not 
waitForElementInDOM(driver, "//*[@name='mobile']", 15); 

//Here will check element is enable or not
boolean enable = elementIsEnable(driver, "//*[@name='mobile']");    
if(enable)
{
driver.findElement(By.xpath("//*[@name='mobile']")).click();
}
else
{
System.out.println("Element not visible. Please increase your waiting time");
}
}

----------------------------------------------------------------------------

public void waitForElementInDOM(WebDriver driver,String elementIdentifier, long 
timeOutInSeconds) 
{       
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds );
try
{           
//this will wait for element to be visible for 15 seconds        
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.xpath(elementIdentifier))); 
}
catch(NoSuchElementException e)
{           
e.printStackTrace();
}           
}

-------------------------------------------------------------------------------

public boolean elementIsEnable(WebDriver driver, String elementIdentifier)
{
WebElement element = driver.findElement(By.xpath("elementIdentifier"));
if(element.isEnabled())
{
return true;
}
else 
{
return false;
}       
}

Upvotes: 0

Related Questions