Unsolved Alternative to click on this QWebElement?
-
I have a html button that none of the methods I've tried before and worked does work for this one.
The HTML (toOuterXml() output) look like this:
"<input name="ctl00$foo" type="text" class="rcbInput radPreventDecorate rcbEmptyMessage" id="foo" value="Select something" readonly="readonly" autocomplete="off">"
I've tried all thise to click:
- input.evaluateJavaScript("this.click()");
- input.evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);");
- mouseClick(windowHandle(), input);
where mouseClick is defiend as following:
void mouseClick(QWindow *window, const QWebElement &e) { QRect pos = e.geometry(); QPoint clickPoint(pos.x(), pos.y()); QTest::mouseMove(window, clickPoint); QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, clickPoint, 100); }
and input is
auto input = page() ->mainFrame() ->documentElement() .findFirst(QString("input[id='foo']");
Can someone point out the reason why it isn't workng? or provide a working alternative? I have no idea why the regular methods isn't working.
-
@Bob-Asm2
Umm, how is<input type="text">
a "button"? It's an edit control. (It's also readonly.) What are you expecting to happen on clicking it? -
If you just want to set focus of the element, use
QWebElement::setFocus
-
@Konstantin-Tokarev
Since as I pointed out his element isreadonly
, and http://doc.qt.io/archives/qt-5.5/qwebelement.html#setFocus:Gives keyboard input focus to this element
I'm not sure/would not have thought that would have much effect, for whatever the OP is trying to achieve.
-
on GUI interface, when it's clicked, a list of suggestions (a set of HTML li tags) is shown. This is what I'm trying to do programatically. I'll give a try to setFocus() but it has been unsuccefully on the past, so I've since always used evaluateJavaScript("this.focus()") instead of.
-
@JonB What happens with that page is it seems a "hack" HTML it's of type text but on GUI appers to be a select and when you click on it it show a list of options, in form of autocompleter. I just want to click on it and display that autcompleter.