I recently wrote an article titled: Building a Simple Web Browser in C++ using Qt, in which I described building a very basic web browser in C++ using the Qt framework (as the name implies). Many of my readers noted this is very basic, almost too basic and is about as good/useful as the Qt tutorials. I agree with my readers, it was very basic, but it allows me to build off that post to build something a tad more cool.
Lately, I have been doing QA (quality assurance) and one of the “job descriptions” is inspect the web elements you would like to test on. There are two basic methods to obtaining web elements:
- Go to a webpage right click -> inspect webpage and literally read the code
- Use an application/plugin such as Firebug, a plugin which inspects the element for you.
My goal was to create my own Firebug style application in Qt which will store/print all of the web elements into an excel spreadsheet, as well as all the items I click and all the characters I enter. This should allow me to more easily write automated test cases at a later time.
Review and Additions to The Basic Web Browser
I recommend first reading about creating a simple web browser in Qt from my previous written article. This article is an extension, in which I explain the “refresh,” and progress bar. Adding the progress bar was the most fun:
Creating a progress bar pretty easy and what I did, was place the location of the progress bar after the URL and only made it visible when the progress is loading (at the same time I make the URL bar disappear). All you then have to do is call the following function when: on_urlLineEdit_returnPressed() is called, or when a URL is called:
The refresh button also uses the on_urlLineEdit_returnPressed(), via the following function:
Accessing Web Elements
Determining the web element currently being pressed by the user is pretty difficult, as it turns out. There was not very many articles related to this and as such I decided to write one. The basic premise is the following:
- Take a general QWebFrame, which displays a webpage
- Create an alert or call at Qt function
I then can simply take the QWebFrame from my webView and call injection function:
I do this as the progress bar is loaded, prior to the setting the new frame to visible:
Now, every time I click anywhere on the page with a web element (everywhere), I can see the various characteristics (the red dot being where I pressed):