Tuesday, October 23, 2012
Earlier versions of Selenium most of us ended up using Thread.Sleep()
To wait for objects to render the page fully so that we can access the object from the DOM else Selenium would fail with errors for No such Element
Here is an example of how to use implicit wait using WebDriver FindElement
Code snippet for a single element
Code snippet for multiple elements
Most of the webpages have jQueries running some take longer to load,If a page doesn't load in 60 seconds then it is never going to load
here is the code snippet
public bool IsPageLoaded(IWebDriver driver)
//First wait for the browser to register the new URL;
if (driver.Url.Equals(OldUrl, StringComparison.OrdinalIgnoreCase))
log.Debug("Waiting for Page to load. Current URL: " + driver.Url);
//Second wait for JQuery to become available.
return (bool)executor.ExecuteScript("return CF.isReady;");
log.Error("Caught InvalidElementStateException. Assume page not yet loaded and continute waiting.");
Most of us want our logs to be written to a file externally.
Whether they are application logs,console logs.
In our case have used to grab the logs for the WebDriver C# bindings using the log4net.dll's
Below are step by step instructions as to go about using log4net :
1. Add a config section in the app.config file under configuration
2. Add a appSettings section where you define a key value pair
Which would facilitate ConfigurationManager to get the value
3. I have created a config file other than that of the app.config & named it as log4net.config - below is the configuration
Have used RollingFileAppender and specified a location where these logs are to be written.
RollingFileAppender - This is just like LogFileAppender with an exception doesn't create a new file
Until it has reached the MaximumFilesize that we have configured initially
4. The below code snippet shows how we need to initialize the logger
private static readonly ILog log = LogManager.GetLogger(typeof(
5. Now accessing the key value pair from the app.config file