Selenium C# WebDriver: Wait until element is present
Alternatively you can use an implicit wait:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
An implicit wait is to tell WebDriver to poll the DOM for a certain
amount of time when trying to find an element or elements if they are
not immediately available. The default setting is 0. Once set, the
implicit wait is set for the life of the WebDriver object instance.
C# Selenium wait until element display is equal to none - works only on debug
I've solved it by myself.
It was needed to check at first if the element was visible (By locator), so I could check then if it was not visible. The element probably blinks at page before being shown definitely on page:
WebDriver.WaitForElementIsVisible(By.Id(profilePage.LoadingStateLocator));
WebDriver.WaitForElementIsNotVisible(profilePage.LoadingStateImg);
WebDriverWait how to wait until an item exists or doesn't exist?
This will work for you, I think.
public bool SummaryDisplayed()
{
try
{
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
var myElement = wait.Until(x => x.FindElement(By.Id("summaryPage")));
return myElement.Displayed;
}
catch
{
return false;
}
}
Selenium wait until one of two elements are visible
Update the line as below
IWebElement waitresponse = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("xpath1|xpath2")));
Selenium Wait Until using Element rather the By
I will attempt to answer given the original problem, which was needing to test for visibility, but this required you to update a locator in two places.
The answer is insanely simple: define a instance field for the locator:
public class SomePageModel
{
By siteInUseLocator = By.ClassName("site-txt");
IWebElement SiteInUse => DriverContext.Driver.FindElement(siteInUseLocator);
...
}
Then later on you can reuse this field to test for visibility:
WaitHelpers.WaitTillVisiible(siteInUseLocator);
Related Topics
How to Convert Image to Byte Array
Best Practices For Catching and Re-Throwing .Net Exceptions
Reading an Integer from User Input
Deciding Between Httpclient and Webclient
Validating an Xml Against Referenced Xsd in C#
Detect If Deserialized Object Is Missing a Field With the Jsonconvert Class in Json.Net
Saml Assertion in a Xml Using C#
How to Start a Process as Administrator Mode in C#
How to Find the Number of Cpu Cores Via .Net/C#
How to Split CSV Whose Columns May Contain ,
What Are the Pros and Cons to Keeping SQL in Stored Procs Versus Code
Replace Line Breaks in a String C#
Dynamic Where Clause (Or) in Linq to Entities
Converting String to Byte Array in C#