What would cause a click operation to timeout after 60 seconds? - c#

What would cause a click operation to timeout after 60 seconds? I get an exception thrown, even though the element is clearly displayed in the page and is clickable (I have a ExpectedConditions.ElementToBeClickable check before the click). OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://grid:4444/wd/hub/session/9e9693f0-0288-47a1-97f9-8f61c300bc41/element/29/click timed out after 60 seconds. ----> System.Net.WebException : The operation has timed out
WebDriverWait wait = new WebDriverWait(this.driverController.driver, TimeSpan.FromSeconds(30.00));
IWebElement clickThis;
wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("elementId")));
clickThis = this.driverController.driver.FindElement(By.Id("elementId"));
clickThis.Click();
The exception occurs at clickThis.Click()
Thanks,

Your exception indicates that it is the selenium grid hub that causes the timeout. The hub itself has a timeout, which works as described in the selenium documentation and below:
-timeout 30 (300 is default) The timeout in seconds before the hub automatically releases a node that hasn't received any requests for
more than the specified number of seconds. After this time, the node
will be released for another test in the queue. This helps to clear
client crashes without manual intervention. To remove the timeout
completely, specify -timeout 0 and the hub will never release the
node.
If the issue would have been related to finding the element you wish to interact with, you should have receive a NoSuchElementException or similiar.

Related

WebDriverWait behave like it doesn't wait

I'm getting an exception
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element
Although I'm using WebDriverWait for 10 seconds, it throws exception very fast (almost immidiatly).. like it doesn't wait. At all.
var waitForElement10Sec = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
waitForElement10Sec.Until(ExpectedConditions.ElementIsVisible(By.Id("myForm")));
This is a div which is a wrapper for an input checkbox. All these tags rendered after another button click, then I try to wait before continue. First I tried to wait for the checkbox itself to be clickable but got the same excpetion, so then tried to wait for his parent.
waitForElement10Sec.Until(ExpectedConditions.ElementIsClickable(By.Id("myChkbox"))).Click();
Note - sometimes it success, sometimes it doesn't. I can't point on a cause or different.
I'm using latest nuget package,
.NET framework 4.6
Chrome v108
I'm using the following extension method which works for me;
internal static class WebDriverExtensions
{
public static IWebElement FindElement(this ChromeDriver driver, By by, TimeSpan timeout)
=> FindElement((IWebDriver)driver, by, timeout);
public static IWebElement FindElement(this IWebDriver driver, By by, TimeSpan timeout, TimeSpan pollingInterval = default)
{
// NOTE Also see: https://www.selenium.dev/documentation/webdriver/waits/
var webDriverWait = new WebDriverWait(driver, timeout)
{
// Will default to the DefaultWait polling interval of selenium which is as of writing half a second
PollingInterval = pollingInterval
};
// We're polling the dom, so this is normal procedure and not an exception.
webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
return webDriverWait
.Until(drv => drv.FindElement(#by));
}
}
Try that out. The key here is that you ignore the exception and just loop untill the element can be found.
Since you did not share all your Selenium code and not a link to the page you are working on we can only guess...
So, since simetimes it works and sometimes not there are several possible issues that can cause that:
Your internet connection is too slow or the page you working on is too slow etc. Try increasing the timeout from 10 to 30 seconds.
The element may be on the edge of visible veiwport (screen area detected as visible) - try scrolling that element into the view.
There are more possible issues, but we need to debug your actual code to give better answer

Selenium can not proceed as chrome Does not loads UI

Sometimes, Selenium C# launches chrome as well as the website, but is unable to interact with it.
On close inspection, I noticed that it was because chrome was not in focus and was not loading the UI.
As soon as I focused the chrome, I would see a white screen for half a second, and then UI appeared. And as soon as UI appeared, the test started running well.
I feel like chrome can not get enough system resources without the background. Any help would be appreciated. I never faced the issue in selenium-python.
Website is - web.whatsapp.com
It look like you are not giving enough time for page to load. You can use any of the below wait technique.
Explicit Wait in Selenium C#
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
String ele_xpath = "<xpath of element>"
WebDriverWait wait = new WebDriverWait(driver,30);
IWebElement welcomeMessage =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.XPath(ele_xpath)));
// Here I have assumed first page is having a welcome message, you can use any element present on your page. Your script will wait up to 30 sec for element to appear before it will throw timeoutexception
implicit wait in Selenium C#
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//Above will make script to wait for each element up to 30 sec
waiting in C#:
You can ask your script to wait for a defined millisecond before executing next line of code:
Thread.Sleep(6000);
# It will for 6 sec
Fluent Wait in Selenium C#
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver)
.withTimeout(30, SECONDS) // this defines the total amount of time to wait for
.pollingEvery(2, SECONDS) // this defines the polling frequency
.ignoring(NoSuchElementException.class); // this defines the exception to ignore
WebElement welcomeMessage= fluentWait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) //in this method defined your own subjected conditions for which we need to wait for
{ return driver.findElement(By.xpath("//*[contains(text(),'Welcome')]"));
}});
Note : You can use any of the above wait method. However each of them have their own advantage/ disadvantage. Please read more about them and difference at below link:
https://www.lambdatest.com/blog/selenium-waits-implicit-explicit-fluent-and-sleep/
Please try the following - it will force focus on Chrome (from the information provided I can assume there a JS event which blocks the page loading or trigger onfocus event).
var driver = new ChromeDriver();
driver.Manage().Window.Maximize(); // will focus or at least bring to front
// other things to try - switch
driver.SwitchTo().DefaultContent();
driver.SwitchTo().ActiveElement();
// other things to try - JavaScript
((IJavaScriptExecutor)driver).ExecuteScript("document.querySelector('body').focus();")

How is TimeBuffer property used in RetryPolicy object in Azure Service Bus client?

I have read the documentation and all details about how RetryPolicy object is used in Azure Service Bus Queue Client are clear to me, except one: TimeBuffer property.
Definition in the documentation says:
"The termination time buffer associated with the retry. Retry attempts
will be abandoned if the remaining time is less than TimeBuffer."
But, what is the "remaining time"? Can someone give an example of how is this used?
Here is how I see the situation: If the request fails and error is transient, operation will be repeated until success or until MaxRetryCount is reached. In the meantime intervals between attempts will grow depending on MinimalBackoff and DeltaBackoff until MaximumBackoff reached. From that point, intervals between attempts will be constant and equal to MaximumBackoff. How is TimeBuffer used in this scenario?
One more thing I forgot, so, I edited the question. How to set DeltaBackoff and TimeBuffer when only constructor that allows setting those values is obsolete, and DeltaBackoff property has no setter and is readonly?
TerminationTimeBuffer is a property that is used to limit the total time for the operation to complete.
The termination time buffer associated with the retry. Retry attempts will be abandoned if the remaining time is less than TimeBuffer.
Consider a scenario with following configurations
MinimumBackoff = 0
MaximumBackoff = 30 sec
DeltaBackoff = 300 msec
TimeBuffer = 300 msec
MaxRetryCount = 2
It works as
Attempt 1: Delay 0 sec
Attempt 2: Delay ~300 msec
Attempt 3: Delay ~900 msec
Here the "remaining time" after the 2nd attempt would be 29.7 sec and 29.1 sec after the 3rd attempt.

Quick check if WCF endpoint is available (and how to handle if not)

I have a very simple WCF service running.
An ASP.NET web application is consuming this service from code behind during pageload like this:
try
{
using (var myWCFClient = new MyWCFClient())
{
int myInt = myWCFClient.GetValue();
}
}
catch (Exception ex)
{
}
Where "MyWCFClient" is the proxy object which is autogenerated when adding a service reference to my project.
Everything works fine, but the problem is when the Service Endpoint is down for some reason, it takes more than 30 seconds for the EndpointNotFoundException is catched. Of course this is unacceptable because it delays pageload since everything is synchronous. And because i have no simple mechanism to push the data to the page async after pageload, an async call to the WCF service is not preferred.
I also tried to set the sentTimeout in web.config to 5 seconds, but this doen't solve the problem.
When is set the OperationTimeout of the InnerChannel to 5 seconds like this...
((IContextChannel)myWCFClient.InnerChannel).OperationTimeout = TimeSpan.FromSeconds(5);
...i do get a TimeOutException, but this exception is not throwed within 5 seconds, it also takes more than 30 seconds...
Does anybody knows how to handle this situation, or is there a way to quick check if the service is running before doing the actual call???
We use a ping function on the host that simply returns True in the response payload, and if you response takes longer than 5 seconds, we throw our own exception and exit the process. All the logic is on the client side, minus the Ping() function. We don't wait for the timeout exception.

RedisResponseException from BlockingDequeue

I am getting what looks like a timeout exception when using a BlockingDequeue on a RedisTypedClient.
The calling code looks like
using (var client = ClientPool.GetClient())
return client.As<TMessage>().Lists[_channel].BlockingDequeue(timeout);
Where the timeout is set to 0 and the ClientPool is a PooledRedisClientManager.
The stack trace looks like
ServiceStack.Redis.RedisResponseException: No more data, sPort: 51100, LastCommand:
at ServiceStack.Redis.RedisNativeClient.CreateResponseError(String error)
at ServiceStack.Redis.RedisNativeClient.ReadMultiData()
at ServiceStack.Redis.RedisNativeClient.SendExpectMultiData(Byte[][] cmdWithBinaryArgs)
at ServiceStack.Redis.RedisNativeClient.BRPop(String listId, Int32 timeOutSecs)
at ServiceStack.Redis.Generic.RedisTypedClient`1.BlockingDequeueItemFromList(IRedisList`1 fromList, Nullable`1 timeOut)
at ServiceStack.Redis.Generic.RedisClientList`1.BlockingDequeue(Nullable`1 timeOut)
From what I can find, this is an issue with the client holding an open connection. I thought this was supposed to be fixed by using the PooledRedisClientManager, but it seems to still happen. The issue is easy to reproduce. Simply call the BlockingDequeue method and wait about 2-3 minutes and the exception throws.
I had this once on Windows Azure and on redis i did config set timeout 30 and in ServiceStack.Redis i did
var redisFactory = new PooledRedisClientManager(redisConn);
redisFactory.ConnectTimeout = 5;
redisFactory.IdleTimeOutSecs = 30;
And now for some reason it works
It turns out we were sending our Redis requests through a dns entry that was pointing towards an F5 Big IP traffic controller that was setup to drop idle connections after 300 seconds. Once we increased the timeout on the Big IP the error stopped occurring.

Categories

Resources