Can I ignore the WebElement returned through WebDriverWait and ExpectedConditions?

17 views
Skip to first unread message

Debanjan Bhattacharjee

unread,
Jun 5, 2018, 10:44:20 AM6/5/18
to Selenium Users
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
Reply all
Reply to author
Forward
0 new messages