Reputation: 49
I am using Windows 8, IE 10 (java - WebDriver 2.37.0) and I am trying to wait until the element is loaded on the page. I used following code:
WebDriver driver = new FirefoxDriver();
driver.get("http://abc.com");
WebElement myDynamicElement = (
new WebDriverWait(driver, 10).until(
ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
But it's throwing a timeout exception. If I remove this code, it's able to identify the element on the webdriver.
I tried the same code in other browsers as FireFox, Chrome but its still throwing error.
Any help is appreciated.
Thanks
Upvotes: 2
Views: 13777
Reputation: 3707
public static void waitForElementToAppear(Driver driver, By selector, long timeOutInSeconds) {
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(selector));
}
Upvotes: 0
Reputation: 421
You're assigning that wait to the variable myDynamicElement. If you don't give the WebElement variable something to do, Selenium will throw that timeout exception. If you just want to wait for the element to be present then there is no need to assign it to a WebElement variable.
WebDriver driver = new FirefoxDriver();
driver.get("http://abc.com");
new WebDriverWait(driver, 10).until(
ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
If you need to assign that variable for later use then do something with the element.
WebElement myDynamicElement =
new WebDriverWait(driver, 10).until(
ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));
myDynamicElement.isDisplayed();
Upvotes: 2