Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Webdriver wait on element click?

I have been searching for a solution for this, but to no avail. I have a button I'm clicking, that is sometimes taking a long while to return data, and the driver is timing out and just killing the app I guess.

I am trying to use the WebDriverWait class to accomplish this, but the Click() method is not available in the way I'm using it.

WebDriverWait wait = new WebDriverWait(browser, new TimeSpan(0, 5, 0));

bool clicked = wait.Until<bool>((elem) =>
{
     elem.Click(); //Doesn't Work
     return true;
});

The ImplicitlyWait() method is only for waiting for elements to load, but this times out on Click(), so it can't even look for an element.

The SetScriptTimeout() method just works with executing javascript, which I'm not doing.

Does anyone know of a way to do this?

like image 595
hacket Avatar asked Mar 08 '12 14:03

hacket


1 Answers

try this :

WebDriverWait wait = new WebDriverWait(driver , 1000) ;
wait.until(ExcepctedConditions.elementToBeClickable(ById("element"));

Element can be ID of any element present on the next page you are redirected to . Once Page loads fully then it will start executing your code .

like image 113
WomenInTech Avatar answered Sep 19 '22 17:09

WomenInTech