What is the best way to use I have been getting Timeout exception and below is the code I am using to FindElement.
if i use Thread.Sleep(8000) or 6000 its working as excepted but Its scattered all over my code and its hard to maintain ... is there any elegant solution for this problem?
public IWebElement GetFindElement(By locator)
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
{
return d.FindElement(locator);
});
return myDynamicElement;
}--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/oEM90wjhcLkJ.
For more options, visit https://groups.google.com/groups/opt_out.
You are missing one of the big reasons to not use Thread.sleep, all computers are different specs and different speeds, a sleep of 8 seconds may be enough time on your computer, but put it on one that is half as powerful and the tests will never pass.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/J7g_syL7LvAJ.
Thank you very much for the detail response.I forgot to tell you that, it does refresh the page before i start selecting a different elementso i have two dropdownlist and both do the postback meaning refresh the pageso for the first dropdownlist i do not have problem selecting the selectText from the dropdownlist but when my code try to select the second dropdownlist then it throws an error after debuggin my code i found that, once i select the first dropdownlist the page is refreshing ....how to find a way to synchronize on the DOM .... where/how should i start looking any clue?
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/TDTvbP2LI6cJ.
In your situation I would be using the page factory stuff in the support packages, unfortunately the stuff I have is quite Java specific and I don’t know what the equivalent code would be in .NET. The below may help or it may not be relevant to your specific language binding:
http://code.google.com/p/selenium/wiki/PageFactory
The advantage of using a page factory is that the element is found again every time you use it (unless you specifically cache it) so you should no longer see StaleReferenceElementExceptions.
This came up on the Selenium blog a while back and is supposed to be a C# implementation based around page objects so may be of some use to you:
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of Abu Hamzah
Sent: 19 October 2012 04:17
To: seleniu...@googlegroups.com
Subject: Re: [selenium-users] Thread.Sleep is better then using WebDriverWait/Implicitly or Explictly ?
okay so i come-up with this code after reading and goggling but still does not work ERGGGGGGGGG
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/Acg60O3u_20J.
how often it polls for the condition
Subclass DefaultWait<T>. Or you could customize your WebDriverWait instance. The WebDriverWait class has properties and methods for customizing almost everything about the wait, from the total wait timeout, to how often it polls for the condition, to what exceptions it will ignore when executing the Until() method.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/DFFLDgY1d94J.
Can you show me the test and the page factoryyou are currently using
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/V6Bb2CBRfbUJ.
Hi,I am not sure if this could help you but could not resist myself from posting this.I use driver.findelements(bysomething) if not found then wait for few seconds and then repeat the same statement if element not found then fail the test as there will be no errors or exceptions will be reported code snippet below.public static boolean exists(By elementExpr){try {status2=false;getDriver().manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);status2= Elements(elementExpr).size() != 0;getDriver().manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);}catch (WebDriverException e) {writeLogs("Element Search Failed :" + e.getMessage());Assert.fail("Element Search Failed - Exception :" + e.getMessage());} finally{}return status2;}Thanks,Anand
Without knowing the exact code for the page you're running against, no, I can't help you any further. I've explained exactly what the issue is. You're finding the element before the DOM refreshes, so when you try to use it, it's stale. You'll need to find a way, within the context of the application you're automating, to account for the behavior. I wish I had a better, one-size-fits-all, just-do-this-and-I-guarantee-it-will-work-100%-of-the-time solition, but I don't. There may be someone in the community who can provide you with that level of code without intimate knowedge of your application code, but I'm not it.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/a2xx3XqWNnUJ.
var driver = new FirefoxDriver();
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/cfdXMa0COWYJ.
public WebElement findElement(By by){ _driver.manage().timeouts().implicitlyWait(20000, TimeUnit.MILLISECONDS); long startMs = System.currentTimeMillis(); WebElement element = _driver.findElement(by); long endMs = System.currentTimeMillis(); long searchTime = endMs - startMs; if(searchTime >= 10000){ log().debug("Item Found. Search Time: " + searchTime + "ms."); } return element; }Abu,