Need to wait for finding specific element on loading webpage - selenium 3.141.5 and java 8

309 views Asked by At

Using selenium 3.141.5 (Latest) and java 8. Now I have a situation where I need to wait for particular element on webpage to get loaded before I execute next line. I am trying to use ExpectedConditions java class but unable to import this. In the javadoc of selenium I can find ExpectedConditions and ExpectedCondition. [PSB]

static ExpectedCondition<WebElement> presenceOfElementLocated(By locator)

An expectation for checking that an element is present on the DOM of a page.

I am not using any maven or any other tool. it is just eclipse, java and selenium. Image from my local eclipse

Please help for the same. I just want to wait for particular element to get loaded before I execute my next line of code with latest selenium and java. Thanks in advance! :) I hope I have tried to explain well if not then sorry

2

There are 2 answers

1
pburgr On

I'm using ExpectedConditions:

// modified wait method
public WebDriverWait wait_sec(WebDriver driver, int sec) {return new WebDriverWait(driver, sec);}

// example of usage one of ExpectedConditions
driver.get(url_portal);
WebElement fld_pwd = wait_sec(driver, 60).until(ExpectedConditions.elementToBeClickable(By.name("password")));
fld_pwd.click();
fld_pwd.sendKeys(sec_var.getPwd());

// example of negative usage
wait_sec(driver, 300).until(ExpectedConditions.not(ExpectedConditions.urlContains("#")));

Exploring ExpectedConditions was trully essential for my tests.

0
Atul Ranjan On

I switched to selenium 3.11 and now everything is working as expected!. There I can use ExpectedConditions

Thanks