Is it possible for waiting multiple elements with timeout?

I’m going to define a keywork like this
def waitForMultiplesElementsVisible(TestObject object1, TestObject object2, int timeout)

Can someone help please?
Many Thanks

You can read the source of WebUI.waitForElement keyword here:

Here is the source of WebUI.waitForElementPresent keyword with timeout:

You can learn them and twist them as you like:

Perfect @kazurayam

but it seems I have some issue with my code below, it still not working for object2 …
I mean I need one of the two elements is visible and the scripts continue running…
Can you please help?

class WaitForMultipleElements {

def waitFor2ElementVisible(TestObject to,TestObject to2, int timeOut) {

	WebDriver driver = DriverFactory.getWebDriver()
	timeOut = WebUiCommonHelper.checkTimeout(timeOut)
	try {
		WebElement foundElement = WebUIAbstractKeyword.findWebElement(to, timeOut)
		WebElement foundElement2 = WebUIAbstractKeyword.findWebElement(to2, timeOut)
		WebDriverWait wait = new WebDriverWait(DriverFactory.getWebDriver(), timeOut)
		foundElement = wait.until(ExpectedConditions.visibilityOf(foundElement))
		foundElement2 = wait.until(ExpectedConditions.visibilityOf(foundElement2))
		if (foundElement != null || foundElement2 != null) {
		return true
	} catch (WebElementNotFoundException e) {
		return false
	} catch (TimeoutException e) {
		return false


Many Thanks

Well, I have never tried this sort of thing. I have no practical/running solution.

Just I think, … let me assume you provide 30 seconds as the timeout for the keyword,

In the method implementation, I would make the method something like this

(0) start StopWatch to measure the time taken, and start an infinite loop

(1) in the loop, if the time already expired 30 seconds, then exit the loop and return false

(2) call wait for element 1 with timeout of 3 seconds
- if found return true
- if not found (caught an Exception raised) continue to (3)

(3) call wait for element 2 with timeout of 3 seconds
- if found return true
- if not found (caught an Exception raised) continue to (1)

The idea is, you internally create short time slices in which you repeat waiting for the visibility of each individual HTML elements until the total time taken exceeds the limit. This idea comes from the decades-old Time sharing system.