SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Request to set implicit wait as a basic parameter to a keyword

Open vyvy3 opened this issue 1 year ago • 1 comments

Prerequisites

  • I have searched for similar issues in open tickets and cannot find a duplicate.
  • The issue still exists against the latest released version of SeleniumLibrary.
  • This is not a usage question or support request. For those, see more details in README.rst: https://github.com/robotframework/SeleniumLibrary#support
  • You are not using the Java Selenium2Library: https://github.com/MarketSquare/robotframework-seleniumlibrary-java
  • Remember that this is a public forum, so remember to remove all sensitive information, like username and password.

For issues

Steps to reproduce the issue

Our team uses 1.5 min as a basic implicit wait. Sometimes, we need to get results immediately (e.g., is there an element on the page). Since implicit wait is set globally we are failing to structurize scripts nicely and are forced to proceed with the following workaround where we change the global wait, run the keyword, and set it back:

${orig}=  Get Selenium Implicit Wait
Set Browser Implicit Wait    1s
${check_abc}=  Run Keyword And Return Status    Element Should Be Visible    xpath=%xpath%
Set Browser Implicit Wait    ${orig}

or

Set Browser Implicit Wait    1s
${status}=    Run Keyword And Return Status    Page Contains Text    IMAGE_1.png
Set Browser Implicit Wait    ${orig}

Can you please suggest ways to accomplish the same logic without waiting for 1.5 minutes and not playing with that "Set Browser Implicit Wait"? Or maybe there is a possibility to add an implicit wait for a specific keyword execution?

Thank you in advance!

Expected behavior and actual behavior

When I follow those steps, I see... keyword needs 1.5 min for execution

I was expecting... a way to execute a keyword and get result immediately

Environment

Browser: Google Chrome 124.0.6367.63 Browser driver: chromedriver 124.x.x Operating System: Windows 11 Libraries

  • Robot Framework: 6.1.1
  • Selenium: 4.8.2
  • SeleniumLibrary: 6.0.0
  • Interpreter: Python 3.11

This project is not funded by any organisation or company, I do this because I want to do this on my own free time. Therefore if you want feature be implemented, the easiest and usually fastest way usually is to provide pull request. See https://github.com/robotframework/SeleniumLibrary/blob/master/CONTRIBUTING.rst for mode details about project development.

vyvy3 avatar Apr 29 '24 07:04 vyvy3

@vyvy3 A few questions..

  • Have you seen a change in behavior where it was once returning on completion of the implicit wait?
  • Does this use the full time only when you use "Run Keyword And Return Status" or in every instance of a library call using locators?
  • Do you have a reproducible example on a public accessible website?
  • Do you have any other add on libraries which change the SeleniumLibrary functionality (like AngularJSLibrary or SeleniumTestability library)? (Not interested or concerned about all your libraries just those designed to supplement SeleniumLibrary).

emanlove avatar Apr 29 '24 11:04 emanlove

@vyvy3 If you are going to use selenium implicit waits by default it will wait each time the library tries to locate the specified element. So even in calls like Element Should Be Visible the wait will be there due to the universality of the implicit wait functionality. There is not a good way around this while still using the selenium implicit wait.

I do notice that above for both examples you are using the Run Keyword And Return Status and along with, it seems like, validation type keywords. You might be able to make a custom keyword, like Run Keyword And Return Status Without Delay that sets the implicit wait and then call run keyword and return status.

Other than this I would look at your overall waiting strategy. I am going to close this issue. Please reopen if you feel there is something else that we should do.

emanlove avatar Dec 29 '24 21:12 emanlove