Good day! Task: go to the site, fill in the login form fields, click the button, wait for the page, wait for the page to load, wait for the data in the div container, then wait for the change in this container as soon as it changes, read the contents of the html tag, and again wait for change ...
<div class="container"> <audio id="notification"> <source src="../notify.mp3" type="audio/mp3"> <source src="../notify.ogg" type="audio/ogg"> </audio> <div class="col-lg-pull-12 text-center mid-text"> <h4>Live Binary Option Signals</h4> <span>for</span> <span id="last-update">2017-07-20 12:24:14</span> </div> <div class="col-lg-pull-12 sub-heading active-signals" style="display: none;"> <h4>Signals — Active</h4> </div> <div id="active-list" class="col-lg-pull-12 active-signals" style="display: none;"></div> <div class="col-lg-pull-12 sub-heading inactive-signals" style="display: none;"> <h4>Signals — Not Active</h4> </div> <div id="inactive-list" class="col-lg-pull-12 inactive-signals" style="display: none;"></div> <div class="col-lg-pull-12 sub-heading winning-signals"> <h4>10 Most Recent Winners</h4> </div> </div> I found that you can expect "onpropertychange", but I don’t understand where to put it in (I found it:
var body = wb.Document.GetElementById("targetId"); body.AttachEventHandler("onpropertychange", AjaxContainerLoadData); clickLink.InvokeMember("click"); private void AjaxContainerLoadData(object sender, EventArgs e) { var wb = sender as WebBrowser; ... } here, as I understand it, this event is expected after clicking on the button, but I will not have a click on the button, I will not have any changes, the page does not change, the url does not change, but visual changes occur on the page, the element contents change ( id = "last-update"). Found the WebBrowser.TextChanged event, but you also need to start listening to it from somewhere.
My code: I call the form from the console and then processing the button click on the form:
private void Start_Login(object sender, WebBrowserDocumentCompletedEventArgs e) { webBrowser1.DocumentCompleted -= Start_Login; webBrowser1.Document.GetElementById("txtEmail").SetAttribute("value", "email"); webBrowser1.Document.GetElementById("txtPassword").SetAttribute("value", "pass"); Console.WriteLine("start waiting..."); Console.WriteLine(webBrowser1.Version); //нет смысла ждать, но лучше подождать... Thread.Sleep(2000); webBrowser1.Document.GetElementById("btnLogin").InvokeMember("Click"); webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(GetUPD); } private void GetUPD(object sender, WebBrowserDocumentCompletedEventArgs e) { Thread.Sleep(2000); //ждём загрузки div-контейнера Application.DoEvents(); //только после этого заполняются все контейнеры на странице string last_up = ((WebBrowser)sender).Document.GetElementById("last-update").GetAttribute("InnerText"); Console.WriteLine(last_up); webBrowser1.DocumentCompleted -= GetUPD; } private void button1_Click(object sender, EventArgs e) { webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(Start_Login); WebBrowserHelper.FixBrowserVersion(); webBrowser1.Navigate("https://app.binarysignalapp.com/"); }
WebBrowser.DocumentCompleted? - arrowd