selenium icon indicating copy to clipboard operation
selenium copied to clipboard

WebDriverWait or Dynamic wait Support

Open viralkpanchal opened this issue 6 years ago • 2 comments

Hi,

I am trialing out this Selenium with Go. I would like to use WebDriverWait function to wait for an element to be visible / enabled.

For example, I can see this working with Java as mentioned here: https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

Is there a support for this with an example?

Regards, VP

viralkpanchal avatar Aug 15 '19 06:08 viralkpanchal

If you go on the selenium documentation you will find that the signature of Wait is: Wait(condition Condition) error.

Condition is defined as

type Condition func(wd WebDriver) (bool, error)

So we need to construct such a Condition function which returns true when the element is present or not.

In below you will find such an example.

func Enabled(by, elementName string) func(selenium.WebDriver) (bool, error) {
	return func(wd selenium.WebDriver) (bool, error) {
		el, err := wd.FindElement(by, elementName)
		if err != nil {
			return false, nil
		}
		enabled, err := el.IsEnabled()
		if err != nil {
			return false, nil
		}

		if !enabled {
			return false, nil
		}

		return true, nil
	}
}

AntonioL avatar Oct 30 '19 08:10 AntonioL

It says selenium.Wait is not declared @AntonioL :(

samuelnihoul avatar Dec 25 '22 19:12 samuelnihoul