0Day Forums
Selenium C# WebDriver: Wait until element is present - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: C# (https://0day.red/Forum-C)
+--- Thread: Selenium C# WebDriver: Wait until element is present (/Thread-Selenium-C-WebDriver-Wait-until-element-is-present)



Selenium C# WebDriver: Wait until element is present - babakehxtmwabm - 07-24-2023

I want to make sure that an element is present before the webdriver starts doing stuff.

I'm trying to get something like this to work:

WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));
wait.Until(By.Id("login"));

I'm mainly struggling how to setup up the anonymous function...



RE: Selenium C# WebDriver: Wait until element is present - raman743 - 07-24-2023

You can also use

**ExpectedConditions.ElementExists**

So you will search for an element availability like that

new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login))));


[Source][1]

[1]:

[To see links please register here]

"Source"


RE: Selenium C# WebDriver: Wait until element is present - antimonopolists743965 - 07-24-2023

Explicit Wait

public static WebDriverWait wait = new WebDriverWait(driver, 60);

Example:

wait.until(ExpectedConditions.visibilityOfElementLocated(UiprofileCre.UiaddChangeUserLink));




RE: Selenium C# WebDriver: Wait until element is present - weizmann508 - 07-24-2023

new WebDriverWait(driver, TimeSpan.FromSeconds(10)).
Until(ExpectedConditions.PresenceOfAllElementsLocatedBy((By.Id("toast-container"))));


RE: Selenium C# WebDriver: Wait until element is present - Drsparing1 - 07-24-2023

public bool doesWebElementExist(string linkexist)
{
try
{
driver.FindElement(By.XPath(linkexist));
return true;
}
catch (NoSuchElementException e)
{
return false;
}
}


RE: Selenium C# WebDriver: Wait until element is present - undialyzeds863021 - 07-24-2023

Try this code:

New WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(Function(d) d.FindElement(By.Id("controlName")).Displayed)