[solved] QtWebKit - how to find name of radio button
-
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.
-
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>
@ -
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.
-
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;
}
@