I am trying to automate a web page using the gecko engine, it is similar to the webBrowser that Visual Studio has built-in. I am using the event
navegador.DocumentCompleted += (senderx, ex)=>
To wait for the page to complete, I'm fine with everything except an input that sometimes fills it for me and sometimes passes it by, I read it as follows
Gecko.DOM.GeckoInputElement input = (Gecko.DOM.GeckoInputElement)document.GetElementsByName("txtorderNo")[0];
input.SetAttribute("value", "aKl8_Sbl");
input.Value = "aKl8_Sbl";
To avoid skipping it I want to pause, the issue is that I'm having a problem with it, poor different things and nothing works for me
- The IsBusy and IsAjaxBusy methods always return false.
- The "System.Threading.Thread.Sleep" doesn't work for me because it slows down the loading of the browser so it's as if nothing
Using this code makes me wait but I get the following error.
{"Specified argument was out of the range of valid values.\r\nParameter name: index"}
public void Esperar(int tiempo) { DateTime reloj = DateTime.Now; reloj = reloj.AddSeconds(tiempo); while (reloj > DateTime.Now) { Application.DoEvents(); } }
The other two that I use are these but they don't work for me either
async Task Delay() { await Task.Delay(100000); } public void Wait(double seconds) { Timer timer = new Timer(); timer.Interval = (int)(seconds * 1000); timer.Tick += (s, o) => { timer.Enabled = false; timer.Dispose(); }; timer.Enabled = true; }
If anyone has an answer I hope you can help me, greetings
As this answer indicates, you could make one
async Task
quite similar to what you already have:Note that the function is called with a
await
and that the calling function has to beasync
I think that the code you mention fails because it compares with all the time values of the DateTime that go up to milliseconds, although I don't quite understand why it occurs, or what the offset out of range is. If you limit the comparison to seconds, since the wait value is in seconds, it doesn't fail.
- Note: You yourself told me that the error is in the expect method. And what I am referring to is that in the while you had put While (clock > DateTime.Now), which does not compare a second with the current second, but a millisecond, with the current millisecond... while the delay, try to occupy X seconds (and not milliseconds). On the other hand, I don't think Application.DoEvents(); It is not the source of the error at all, because what it does is review and update the control of the other events, avoiding the occurrence of uncontrolled events, or the window interface not being updated correctly for this reason; So I think that Application.DoEvent(); it is very convenient for the assignment you comment to complete properly, especially if you have observed that it got assigned when using that method. There are errors that occur