Selenium FluentWait wait before starting to poll - selenium

I'm using Selenium WebDriver to get some content from a site that dynamically loads it using Ajax. I created a custom Wait class to check for a condition on the page to make sure that the page has loaded before continuing. I used FluentWait to set the polling interval to 2 and timeout to 10. However, I noticed that it checks for the first time at time increment 0, then waits 2 seconds if the condition was false, then checks again, etc.
Since the page takes some time to load, it always is false at the first check, but usually is true at the second. Is there any way to make Wait wait the 2 seconds before checking for the first time? I.e. check at times 2,4,and 6, if necessary, rather than at 0,2,4,and 6?
Thanks,
bsg
EDIT
I've been asked to mention why I want this behavior - after all, I'm using the Wait the way it's meant to be used. The benefit I get from it returning true the first time is the following: WebDriver apparently opens a new socket every time it issues a command to the browser. For whatever reason, these sockets don't always get closed after the call executes. When executing a large number of calls in a short time (for instance, when repeatedly checking for a condition, which is what Wait does), it is possible to run out of virtual sockets, and the driver crashes. (The lack of enough virtual sockets seems to be a known issue on Windows 7, but I can't modify my system.)
The fewer calls to the driver I issue in a short period of time, the less likely it is to overrun the number of available sockets. I have observed that the first check never returns true, and therefore it's just opening a socket for no reason, making the program more likely to crash. That's why I want to wait. I hope this explanation is helpful for someone searching for information as to why they keep getting SocketExceptions in WebDriver.

The obvious answer would be to just insert a time.sleep(2) (or similar method) before your first check. Would that work for what you're trying to do?

Related

Selenium: Stability Issue while running multiple instances of chromedriver on one machine

I am running multiple instances of google chrome via (chromedriver) on one machine using multi-threading. When I increase the instance count like 12+ (depending of the machine capacity) I start seeing the following issues
Element is visible on the page but the wait command fails randomly even after waiting for long enough. It says the element is not present on the page. The same code always works if I reduce browser count (I also check the server performance issue, there is none)
Click is performed on the element but the action is not triggered. (We can see the element color changed in the screenshot). In another forum, someone said that JS event binding to element is not completed.
I have two questions:
Is it recommended a large number of instances of Google chrome via chromedriver on the machine?
Is there any possible solution for the above problems
Thanks
Vinay
First resize your window.
If you are using Headless browser then you should give a specific size to your browser.
Try to make own xpath and try to use xpaths instead of css selectors.It may prevent unable click or intercept.
Adjust everything in a proper manner of threading.
If CPU and RAM and everything is ok then try to look towards threading pool.
And about your first questing:-
Yes you can definitely use multiple instances on windows machine.It have the capability . But you have to lookafter PORTS using a single instance.Or you can manually use debugger address and set ports like 9992
Hope thease answer will help you definitely.

How to get Multiple Threading.Timer instances Running in Harmony

Hi there I've got a real pain in the proverbial problem with an app that runs multiple threading.timers as in:
'Instaniate the timer to refresh the memory cache of pi points (tags)
_tagRefreshTimer = New Threading.Timer(New Threading.TimerCallback(AddressOf TagRefresh), Nothing, Timeout.Infinite, Timeout.Infinite)
'Instaniate the timer to check for new files to process
_fileCheckTimer = New Threading.Timer(New Threading.TimerCallback(AddressOf FileCheck), Nothing, Timeout.Infinite, Timeout.Infinite)
'Instaniate the timer to check for dynamic setting changes
_settingsTimer = New Threading.Timer(New Threading.TimerCallback(AddressOf SettingsRefresh), Nothing, Timeout.Infinite, Timeout.Infinite)
Each of the timers can be configured to run at different intervals:
_tagRefreshTimer.Change(_tagRefreshInterval, _tagRefreshInterval)
_settingsTimer.Change(_settingsRefreshInterval, _settingsRefreshInterval)
_fileCheckTimer.Change(_fileCheckInterval, _fileCheckInterval)
I expected that these timers, since they are running in separate threads, would run happily in parallel with each other; however, this has not proven to be the case in practice. What happens is that two of the three will run together, but for some reason the third does not get an opportunity to fire. If I put a break point in the code, and wait for a few seconds, then continue, the third one sometimes does fire, however only at that point, thereafter it disappears into the background.
I'm wondering If I have some sort of race condition going on here, though I have to say as I mentioned at the start since threading.timers run in their own thread and in this context are not conditional on content from the main thread, I was simply not expecting this issue. Anyone have any idea what is going on here and how I might circumvent it?
Ok guys, I've traced the problem to my attempts to pause each of the three different timers using 'Timeout.Infinite' under certain conditions from within the competing callbacks. For example when the tag refresh was taking place I wanted to pause the file check process until the tag refresh had completed, and vice versa. It seems that even though each of the timers was switched back on once the task was completed, something was preventing the timers from acting as expected. Have cleaned up the code now and all timers are firing as expected and callbacks are completing as expected. App is now functioning as intended so consider this query answered. Thanks again for your input :-)
Kind Regards
Paul.

Requests is blocking and waiting for first call to be finished

I have a serious problem, is that I can not launch any query on clicking on some link in my website until the first request is finished:
I have a musical website in which I generate waveform on click on the track, the problem is that generating the waveform take some sometime (about 12 seconds) to be finished, so if I click on another track it will not start untill the generation (the call to the webservice) is not yet finished.
I have seen in FRONT calls but the problem seems to be in backend, because even in the logs of apache, it says that the first query was called at x time, when it finishes apache write down in the log the second call.
The strange thing is that the time of the second call written by apache is the x + some micro seconds, as the apache also was blocked waiting for the first request also to be finished.
Please help me.
BTW : the website is secured by a password so I must have contact with someone to see the problem
Ask me what ever you want for more details.
Kind regards.

Is there any internal timeout in Microsoft UIAutomation?

I am using the UI Automation COM-to-.NET Adapter to read the contents of the target Google Chrome browser that plays a FLASH content on Windows 7. It works.
I succeeded to get the content and elements. Everything works fine for some time but after few hours the elements become inaccessible.
The (AutomationElement).FindAll() returns 0 children.
Is there any internal undocumented Timeout used by UIAutomation ?
According to this IUIAutomation2 interface
There are 2 timeouts but they are not accessible from IUIAutomation interface.
IUIAutomation2 is supported only on Windows 8 (desktop apps only).
So I believe there is some timeout.
I made a workaround that restarts the searching and monitoring of elements from the beginning of the desktop tree but the elements are still not available.
After some time (not sure how much) the elements are available again.
My requirements are to read the values all the time as fast as possible but this behavior makes a damage to the whole architecture.
I read somewhere that there is some timeout of 3 minutes but not sure.
if there is a timeout, is it possible to change it ?
Is it possible to restart something or release/dispose something ?
I can't find anything on MSDN.
Does anybody have any idea what is happening and how to resolve ?
Thanks for this nicely put question. I have a similar issue with a much different setup. I'm on Win7, using UIAutomationCore.dll directly from C# to test our application-under-development. After running my sequence of actions & event subscriptions and all the other things, I intermittently observe that the UIA interface stops working (about 8-10min in my case, but I'm heavily using the UIA interface).
Many different things including dispatching the COM interface, sleeping at different places failed. The funny revelation was I managed to use the AccEvent.exe (part of SDK like inspect.exe) during the test and saw that events also stopped flowing to AccEvent, too. So it wasn't my client's interface that stopped, but it was rather the COM-server (or whatever the UIAutomationCore does) that stopped responding.
As a solution (that seems to work most of the time - or improve the situation a lot), I decided I should give the application-under-test some breathing point, since using the UIA puts additional load on it. This could be a smartly-put sleep points in your client, but instead of sleeping a set time, I'm monitoring the processor load of the application and waiting until it settles down.
One of the intermittent errors I receive when the problem manifests itself is "... was unable to call any of the subscribers..", and my search resulted in an msdn page saying they have improved things on CUIAutomation8 interface, but as this is Windows8 specific, I didn't have the chance to try that yet.
I should also add that I also reduced the number of calls to UIA by incorporating more ui caching (FindAllBuildCache), as the less the frequency of back-and-forth the better it is for the uia. Thanks to the answer of Guy in another question: UI Automation events stop being received after a while monitoring an application and then restart after some time

NotesTimer causes the whole lotus client to flicker

I have a timer that talks to java objects through LS2J. It has only to call some getters of the java objects and to update the GUI with new values. This causes the GUI in iNotes Client to show the "Busy" cursor very shortly when the timer ticks. I is really annoying because it occurs even when another window is open and even in the designer.
I actually have to expect that the functionality in the timer event will get more complicated in the future, so I don't want to solve the problem by making my handler lighter.
Is there a way to tell iNotes client not to show this cursor or even an alternative way to make this regular check without timers?
The NotesTimer class in Notes client (not iNotes) does take over the foreground when it triggers, so there will be a bit of a delay if you do something that takes time to execute. It's possible to set up the Notes client to execute background scheduled agents in local database replicas, so that might be an option. You can to the heavy lifting in background and deposit the results somewhere -- say, in a profile document -- that can be accessed quickly by the UI code.
Alternately, you could try a XPages in the client application. I believe it can do partial refreshes while other stuff is going on.
For the record, I simplified the functionality of the Java call by preparing the data so that the timer only has to read the results. I also made the timer run every 3 seconds instead of 1.
Now I don't see any flicker!