-1

My webpage taking close to 5 minutes to complete the process after clicking a button.

I am using the following code to perform the click

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.example.com")

element = driver.find_element(By.CLASS_NAME, ".buttoncls")
element.click()

120 seconds after the click is performed, I am getting the timeout error at the python end.

In playwright I am able to specify the timeout as parameter to click function call. Is there any such option here in selenium.

I googled for "selenium equivalent for playwright click timeout"

I got the below code snippet through Gemini

wait = WebDriverWait(driver, 10)  # 10-second timeout for the wait

    try:
        element = wait.until(EC.element_to_be_clickable((By.ID, "your_element_id")))
        element.click()
    except TimeoutException:
        print("Element not clickable within the specified timeout.")

Here it gives an option to wait for X seconds before the element becomes clickable. But in my case it has to wait for 5 minutes post clicking the button. There is no issues in identifying and clicking the button. The issue props up after clicking the button.

3
  • 1
    If the URL is public you should post that. Otherwise it's pure guesswork when trying to determine what's going on Commented Sep 12 at 13:33
  • always put full error message (traceback) because there are other useful information. Commented Sep 12 at 15:16
  • @furas - Since I am working on a closed environment and PaaS application, I am unable to share the error message / traceback screenshot. I am able to understand the pain in visualising my issue. Commented Sep 17 at 2:53

1 Answer 1

0

Selenium does not allowing to specify a timeout directly in the .click() function. You can control the timeout and the element wait behavior by using the explicit waits provided by WebDriverWait and expected_conditions.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://www.example.com")
wait = WebDriverWait(driver, 300)
button = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "buttoncls")))
button.click()
wait.until(EC.presence_of_element_located((By.ID, "result")))

you can put short and long timer which wait after button got clicked

wait_short = WebDriverWait(driver, 10)
wait_long = WebDriverWait(driver, 300)

try:
    button = wait_short.until(EC.element_to_be_clickable((By.ID, "your_element_id")))
    button.click()
    
    result_element = wait_long.until(EC.visibility_of_element_located((By.ID, "result_element_id")))
    
    print("Result appeared!")
    
except TimeoutException:
    print("Timed out waiting for the result to be appear.")
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Shiva for the revert. I am getting the error post clicking the button. The control is not coming back to the python program to check the existence of result element. Its just wait for 120 seconds for the process to complete, since its not getting response within that stipulated timeout period, its throwing the error.
You can use two functions short and long timer which wait after button clicked, see the updated changes I have made.
Thanks for your reverts. I am able to resolve it. Will share the code soon here.

Your Answer

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.