I want my code to wait for an element explicitly. i.e. No time limit for waiting. It should wait for an element until that element is found, then whether it takes 1 hour or more.
Asked
Active
Viewed 153 times
-6
-
2Can you show us your existing code? – mjwills Jul 12 '17 at 11:38
-
Maybe you can set maximum waiting time, say `100*100` or something big. – Diabolus Jul 12 '17 at 11:39
-
2what does **element** mean exactly? – Lei Yang Jul 12 '17 at 11:40
-
2How do you "look for" that element? Is it a database query or a webrequest or maybe a file on the filesystem? Can you use async/await, or maybe work with events/listeners? Or simply `while (!found) { Sleep(...); found = checkIfFound(); }`? – Corak Jul 12 '17 at 11:44
-
For example, After login on facebook or any other site I want to wait for an element (it could be LOGOUT button or notification bar) just to confirm that page is completely loaded. @LeiYang – aayush rishi Jul 12 '17 at 12:06
-
In c# we find element by, driverff.findelement(by.id/class("id/class name")); on webpage @Corak – aayush rishi Jul 12 '17 at 12:07
-
Possible duplicate of [Selenium c# Webdriver: Wait Until Element is Present](https://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present) – budi Jul 12 '17 at 21:11
1 Answers
0
You can use do-while loop to wait for that element as it won't appear on screen.
you can take reference of below code.
isElementDisplayed =driver.findElement(By.xpath("element")).isDisplayed();
do{
Thread.sleep(1000);
} while(isElementDisplayed == true)

Ankur Singh
- 1,239
- 1
- 8
- 18