0

So I am trying to do something whilst the progressbar is not 0%. Example

var status = webBrowser1.Document.GetElementById("counter");
if(counter.width > 0%)
{
//CODE
}

And here is the HTML for the bar

 < div class="progress-bar progress-bar-danger" id="counter" style="width: 0%;"></div>

As you might've guess, it's the "width" I want to keep updated but I dont really know how, any help would be appreciated!

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
ackzell
  • 33
  • 9
  • `counter.style.width`? – Daniel A. White Mar 02 '16 at 18:10
  • some more details are required. the progress bar is in webpage? – null1941 Mar 02 '16 at 18:15
  • run a timer in your c# code. For each timer trigger event get the current progressbar percentage completed. then do the required task. – null1941 Mar 02 '16 at 18:16
  • you wanna read width property of HTML element? – null1941 Mar 02 '16 at 18:19
  • function getPerventage { return document.getElementById("counter").offsetWidth;} – null1941 Mar 02 '16 at 18:26
  • call this method from your c# – null1941 Mar 02 '16 at 18:26
  • @null1941 Did'nt work :( there is no method called "offsetWidth" – ackzell Mar 02 '16 at 18:30
  • try document.getElementById("yourDiv").clientWidth; – null1941 Mar 02 '16 at 18:31
  • @null1941 Sadly no... I used this to get textbox value " webBrowser1.Document.GetElementById("betAmount").SetAttribute("value", bet.ToString());" I tried converting with no success... – ackzell Mar 02 '16 at 18:35
  • bro.. can you paste your html page here? try this document.getElementById("yourDiv")[0].offsetWidth – null1941 Mar 02 '16 at 18:37
  • @null1941 I dont own the website, Im just trying to extract some information from it, I already posted the HTML code they use for the progressBar at the question. – ackzell Mar 02 '16 at 18:38
  • what you want to read? You want to read the width of that tag or you want to set width to that tag? – null1941 Mar 02 '16 at 18:39
  • @null1941 I dont really need to ready anything, I just need to call an if statement if the "width:" hits example 70%, so the code would be "< div class="progress-bar progress-bar-danger" id="counter" style="width: 70%;">" – ackzell Mar 02 '16 at 18:41
  • where is this if statement is present? in c# – null1941 Mar 02 '16 at 18:42
  • @null1941 Sorry didn't quite get your question. – ackzell Mar 02 '16 at 18:49
  • you said you want to call and if statement right? Where is this if statement present? is it present in html page javascript ? or is it in c#? – null1941 Mar 02 '16 at 18:51
  • @null1941 Oh! It is in C#, making a small little application. – ackzell Mar 02 '16 at 18:52
  • ok.. that c# does't magically knows about the progress happening in html page. For this start a timer or loop in c#. Keep checking whether progress crossed 70% or not. If it crosses the do whatever required. No question again are you able to get the progress? – null1941 Mar 02 '16 at 18:54
  • @null1941 I already am doing this, but I was wondering if I should use .InnerHTML or .InnerText – ackzell Mar 02 '16 at 18:56
  • are you able to get the progress? I am not understanding why you wanna use InnerHTML or InnerText? – null1941 Mar 02 '16 at 18:57
  • @null1941 No, I do not get any progress at the moment. – ackzell Mar 02 '16 at 19:02
  • http://stackoverflow.com/questions/3103278/can-a-javascript-get-the-value-of-the-div-width-from-a-css-file – null1941 Mar 02 '16 at 19:07
  • @null1941 That is Javascript or I'am missing something since .clientWidth does not exist for me and returns an error. – ackzell Mar 02 '16 at 19:10
  • yes that is javascript. You should put this function "function getPerventage { return document.getElementById("counter").offsetWidth;} " in that HTML page inside script tag. then call this method from c# – null1941 Mar 02 '16 at 19:12
  • http://stackoverflow.com/questions/1437251/calling-a-javascript-function-in-the-c-sharp-webbrowser-control – null1941 Mar 02 '16 at 19:13
  • @null1941 I cant edit the website, Im just extracting information from it. – ackzell Mar 02 '16 at 19:13
  • Ok then.. try load that page in webbrowser control the once it loaded inject the function which i menctioned – null1941 Mar 02 '16 at 19:17
  • http://stackoverflow.com/questions/153748/how-to-inject-javascript-in-webbrowser-control/154496#154496 – null1941 Mar 02 '16 at 19:18
  • after injection this .. try call the injected method to get the width – null1941 Mar 02 '16 at 19:18

1 Answers1

0

Fixed it by changing approach to the problem, found a hidden value not visible for normal users and used that to confirm information.

            var checkValue = webBrowser1.Document.GetElementById("_progressValue");

            if (checkValue.InnerText == value)
            {
                //code
            }
ackzell
  • 33
  • 9