Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. [solved] QtWebKit - how to find name of radio button
Forum Update on Monday, May 27th 2025

[solved] QtWebKit - how to find name of radio button

Scheduled Pinned Locked Moved Qt WebKit
6 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guziemic
    wrote on 6 Sept 2012, 08:03 last edited by
    #1

    Hi,

    I have web page on which there are radio buttons in form. Relevant part of page:
    @
    <form>
    ...
    <tr>
    <td colspan="2" class="input">
    <input class="noborder" name="radiobuttonMH" value="radio2" type="radio"> Radio button 2
    </td>
    </tr>
    ...
    </form>
    @

    My aim is to provide to user all possible choices when he click on one of radio buttons. I am able to find a group of radio buttons within <form> with the same name. But I have problems with values. As you can see on snippet of page value of button is "radio2" and the text visible for user on web page is "Radio button 2". I would like to present on some dialogue window to the user the name visible on web page and not the value. Which can be very different from visible text.

    I already tried some options that QWebElement provide to get this real name but without success.
    Code that I checked:
    @
    qDebug() << "Element " << i << "\nTag" << radioCollection.at(i).tagName()
    << "\nName" << radioCollection.at(i).attribute("name")
    << "\nPlain" << radioCollection.at(i).toPlainText()
    << "\nLocal name" << radioCollection.at(i).localName()
    << "\nPrefix" << radioCollection.at(i).prefix()
    << "\nInnerXml" << radioCollection.at(i).toInnerXml()
    << "\nOuterXml" << radioCollection.at(i).toOuterXml()
    << "\nAttributes" << radioCollection.at(i).attributeNames()
    << "\nNamespaceUri" << radioCollection.at(i).namespaceUri();
    @

    Output:
    @
    Element 1
    Tag "INPUT"
    Name "radiobuttonMH"
    Plain ""
    Local name "input"
    Prefix ""
    InnerXml ""
    OuterXml "<input class="noborder" name="radiobuttonMH" value="radio2" type="radio">"
    Attributes ("class", "onfocus", "onblur", "name", "value", "type")
    NamespaceUri "http://www.w3.org/1999/xhtml"
    @

    Thanks for answers.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stukdev
      wrote on 6 Sept 2012, 08:13 last edited by
      #2

      I don't understand 100%, but the "Radio button 2" is not part of radio button but its a value of a particular cell of the table.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        guziemic
        wrote on 6 Sept 2012, 09:27 last edited by
        #3

        Probably from HTML point of view you are right, but the radio buttons can also be outside table like here
        @
        <form>
        ...
        <input class="noborder" name="radiobuttonMH" value="radio2" type="radio"> Radio button 2
        ...
        </form>

        @

        Then I will be not able to get value of table cell. Thus, I am looking for some general solution.

        And if some one will have such form then I will not have choice and I plan to send value of radio to user. But on web page user will see only circle.

        @
        <form>
        ...
        <input class="noborder" name="radiobuttonMH" value="radio2" type="radio">
        ...
        </form>
        @

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stukdev
          wrote on 6 Sept 2012, 09:49 last edited by
          #4

          Because the web page is not correct. A label tag is need for a radio button for a 'text information'.
          In this case i don't know a good solution. Maybe only an hard parser.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guziemic
            wrote on 6 Sept 2012, 10:47 last edited by
            #5

            Yes, with <label> it is different story. I was not aware about this tag in HTML. Well, I will need to deepen knowledge about HTML. Unfortunately for me, I notice that some of web developers do not use <label> and just write raw text after definition of <input type=radio>.

            Even on most HTML tutorials they do not mention about that tag. For instance "HTML tutorial":http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_RADIO.html

            Thanks.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              guziemic
              wrote on 6 Sept 2012, 11:11 last edited by
              #6

              I also implemented hard parser in following way. But I think it is time consuming operation, as there is a lot of operation related to QString.

              @
              a_oWebElement - input element
              QString CClass::getWebElementInnerText(QWebElement & a_oWebElement)
              {
              QString strRetVal;

              //find text visible on WebPage (need to be stripped from any white space characters
              QString text = a_oWebElement.toOuterXml();
              
              //  qDebug() << text;
              QString strHtml = a_oWebElement.webFrame()->toHtml();
              int position = strHtml.indexOf(text, Qt::CaseInsensitive);
              int tagPosition = strHtml.indexOf("<", (position + text.size()), Qt::CaseInsensitive);
              
              for (int j = (position + text.size()); j < tagPosition; ++j)
                  strRetVal.append(strHtml.at(j));
              
              
              strRetVal = strRetVal.trimmed();
              

              // qDebug() << "innerText - " << innerText << "position" << position << "tagPosition" << tagPosition;

              return strRetVal;
              

              }
              @

              1 Reply Last reply
              0

              1/6

              6 Sept 2012, 08:03

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved