Can I ignore the WebElement returned through WebDriverWait and ExpectedConditions?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Can I ignore the WebElement returned through WebDriverWait and ExpectedConditions?

Debanjan Bhattacharjee-2
Hi All,

I got a simple query, what can be the ideal sequence of events if I ignore the WebElement returned through WebDriverWait and ExpectedConditions?

MVCE:

System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
String xpath = "//*[@id=\"lst-ib\"]";
WebElement element = driver.findElement(By.xpath(xpath));
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(element));
element.click();
element.sendKeys("Hello Selenium");
This block works. But my question is:

As per `WebElement element = driver.findElement(By.xpath(xpath));` the element have a reference to `driver.findElement(By.xpath(xpath));`. WebDriverWait keeps the driver engaged for 10 seconds. How do `element.click();` works if `findElement()` isn't invoked again?

PS: I do believe in the best practices to use the element returned from WebDriverWait. But this is just a query.

Thanks and Regards
Debanjan Bhattacharjee

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4907065e-3a93-4685-a904-609b90899d78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.