Selenium Webdriver wait on element click?

selenium wait for element to load
wait for element to be clickable selenium java
c# selenium wait for element to be clickable
wait command selenium
selenium javascript wait for element
implicit wait in selenium c#
selenium wait for page to load

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?

try this :

WebDriverWait wait = new WebDriverWait(driver , 1000) ;

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 .

Selenium Wait Commands : Implicit, Explicit & Fluent Wait , Explicit Wait in Selenium By using Explicit Wait command, the WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. If one sets an implicit wait command, then the browser will wait for the same time frame before loading every web element. The above code instructs Selenium WebDriver to wait for 30 seconds before throwing a TimeoutException. If it finds the element before 30 seconds, then it will return immediately. After that, it will click on the “Compose” button.

Instead of Click you could try to use SendKeys. Unlike Click, SendKeys does not wait for the page to finish loading before resuming code execution. So you can do something like this:

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

wait.Until<bool>((_driver) =>
     //Check here if results have loaded yet
     return true;

As a side note, I'm pretty sure Until takes in a IWebBrowser as an input, not an element, which is why you can't click on elem.

How to Get Selenium to Wait for Page Load After a Click, More than that, since Selenium webdriver has become more advanced, clicks retry loop in if you try and fetch an element that doesn't exist on the old page: if implicit wait finds the element withing 10 seconds it will start process and will ignore remaining 5 seconds. And if you have applied explicit wait also then explicit wait will also try to find the element even though implicit wait already have found but , you have written the line of code for explicit wait and the line of code will execute and explicit wait will try to find and lets say

In addition to prestomanifesto's solution I can offer a less than ideal solution to that I implemented to solve this issue. It turns out it is throwing an exception - No Response etc... - so I just surrounded it in a try catch then waited for the popup to close, which seems to work fine.

You can substitute whatever you want in your loop, just make sure to put a counter in so it won't loop forever.

      //wait for whatever
      // Wait for 30 seconds for popup to close
    } while (!string.IsNullOrEmpty(browser.CurrentWindowHandle) && cnt < 30);

How to wait for element to be clickable in WebDriver with C# , FireFox and IE can click on the submit button in this scenario but chrome can not. This code works when actaul element is present but selenium is not find it. from contextlib import contextmanager from import WebDriverWait from import \ staleness_of class MySeleniumTest(SomeFunctionalTestClass): # assumes self.browser is a selenium webdriver @contextmanager def wait_for_page_load(self, timeout=30): old_page = self.browser

I use this script :

  private static void waitUntilScriptFoundAndExecute(String script) {
    int tries = 0;
    boolean found = false;
    do {
      try {
        found = true;
      } catch (NoSuchElementException nse) {
        System.out.println("Wait for script NSE (" + tries + ")");
      } catch (WebDriverException wde) {
        System.out.println("Wait for script WDE (" + tries + ")");
      } catch (Exception e) {
        System.out.println("Wait for script E (" + tries + ")");

      // Waiting
      if (!found) {
        System.out.println("Wait for script Not found (" + tries + ")");
    } while (!found && tries < MAX_SCRIPT_WAIT_TRIES);

    if (!found) {
        System.out.println("Script aborted: " + script);

How to wait for element to be clickable in selenium webdriver using , Selenium WebDriver example to show and describe how to wait or pause test Let me remind you one thing is implicit wait will be applied to all elements of test case Click here to view different posts on how to use junit with eclipse for your � Code Implementation for double click operation. from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path

RepeatUntil Extension Method using LINQ Lambda expressions

Copy this code to your project:

public static class SeleniumExtensionMethods
        public static IWebElement RepeatUntil<T>(this T obj, 
             Func<T, IEnumerable<IWebElement>> func, 
                Func<IWebElement, bool> compare,
                  int MaxRetry = 20)
            //call function to get elements
            var eles = func(obj);
            IWebElement element = null;
            while (element == null && MaxRetry > 0)
                //call the iterator
                element = IterateCollection(compare, eles);
                if (element == null)
                    //get new collection of elements
                    eles = func(obj);

            return element;

        private static IWebElement IterateCollection(
           Func<IWebElement, bool> compare, 
           IEnumerable<IWebElement> eles){
            IWebElement element = null;
                ele =>
                    //call the comparator
                    var found = compare(ele);
                    if (found) element = ele;
            return element;

Call it using this syntax:

 // You can change PageObjectType to IWebDriver or IWebElement so that 
 // cb is of any type.
 var element = cb.RepeatUntil<MyPageObjectType>(
    //This is the first function to provide the elements
    p => p.FindElements(By.ClassName("TreeNode")), 
    //This is the comparator
    ele => ele.Text == nodeText && ele.Location.Y>YLocation);

Note: In the example above we are passing in a PageObjectType but you could change this to be of type IWebDriver or event IWebElement. All the type parameter does it allow you to use this as an extension method for the type you specify.

Note the flexibility of the extension method in that the caller can determine the collection as well as the comparator.

thewaiter: clicking on an element by using waits with Selenium , public void click(WebElement element, WebDriver driver, int specifiedTimeout) { WebDriverWait wait = new WebDriverWait(driver,� Purpose: Selenium WebDriver has borrowed the idea of implicit waits from Watir. This means that we can tell Selenium that we would like it to wait for a certain amount of time before throwing an exception that it cannot find the element on the page. We should note that implicit waits will be in place for the entire time the browser is open.

Selenium WebDriver Wait commands | Selenium Tutorials, Selenium-WebDriver Wait commands covers ImplicitlyWait, FluentWait, ExpectedConditions, This means that any search for elements on the page could take the time the implicit wait is set for. Java 3) Click on the Button “ Timing Alert”. An implicit wait instructs Selenium WebDriver to poll DOM for a certain amount of time, this time can be specified, when trying to find an element or elements that are not available immediately. The default setting is 0 seconds which means WebDriver will not wait before any operations on element.

Implicit and Explicit Wait in Selenium WebDriver (Types of Selenium , xpath("//div[contains(text(),'COMPOSE')]")).click();. The above command waits for a stipulated amount of time or an expected condition to occur� We pass in the condition as a function reference that the wait will run repeatedly until its return value is truthy. A “truthful” return value is anything that evaluates to boolean true in the language at hand, such as a string, number, a boolean, an object (including a WebElement), or a populated (non-empty) sequence or list.

WebDriver Implicit, Explicit and Fluent Wait Examples, What is the difference between implicit wait, explicit wait and fluent wait in WebDriver? More specifically, what is the relation between WebDriverWait and FluentWait? Here are examples of We would normally use explicit wait if an element takes a long time to load. Selenium Click Link By href Value. This is the easy and standard way to click elements using Selenium WebDriver. However, it will work only ifthe targeted element existsand is visibleon the page. Otherwise, the WebDriver will throw exceptions. This is when programmers pull their hair out.