Webelement click does not work
-
Yes, but it does not work too.
[ Qt ]
webView = new QWebView;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(webView);
[ ... ]
QWebElement el = webView->page()->mainFrame()->findFirstElement("#tool_open");
el.evaluateJavaScript("this.click()");the click() action doesn't work
With an another Qt code, I can call a Javascript function, but all actions (click, mouse events...) don't work :
[ Javascript ]
function test()
{
alert('clic');
document.getElementById('tool_open').click();
}I have Js pop-up "clic" but the click() action on the webelement 'tool_source' doesn't work...
@fgdevel
QWebElement el = webView->page()->mainFrame()->findFirstElement("#tool_open");
Does this return the exact element that you wanted ?
You can just doqDebug() << el.toPlainText(); //prints the button text
If this works then
evaluateJavaScript
should work too. -
wrote on 20 Aug 2015, 08:17 last edited by
yes, already tried qDebug() << el.toPlainText();
and it works... -
wrote on 20 Aug 2015, 08:21 last edited by
oh no it doesn't work !
-
wrote on 20 Aug 2015, 08:43 last edited by
[ Qt ]
QWebElement el = webView->page()->mainFrame()->findFirstElement("#tool_open");
qDebug() << "WebElement : " + el.attribute("type");it works, el.plainText does not work for this kind of webelement
el.evaluateJavaScript("this.click()");
it does not work
-
[ Qt ]
QWebElement el = webView->page()->mainFrame()->findFirstElement("#tool_open");
qDebug() << "WebElement : " + el.attribute("type");it works, el.plainText does not work for this kind of webelement
el.evaluateJavaScript("this.click()");
it does not work
el.plainText does not work for this kind of webelement
It works too. It will print the list's text.
Also for list click() works.
What are you trying to do on click ? Can you post you HTML code which doesnot work ? -
wrote on 20 Aug 2015, 09:38 last edited by
I try to simulate a webelement click thanks Qt.
In a web navigator the 'tool_open' click() opens an another web page (with javascript code...). I would like to do the same (simulate mouse clic) with Qt.
[ HTML ]
[ ... ]
<ul>
<li id="tool_clear">
<div></div>
Nouvelle Configuration
</li>
<li id="tool_open" >
<div id="fileinputs">
<div></div>
</div>
Open Image
</li>
</ul>
[ ... ] -
wrote on 20 Aug 2015, 09:45 last edited by
and yes the el.plainText works (I tried with an <input> HTML element instead of <li>...)
-
I try to simulate a webelement click thanks Qt.
In a web navigator the 'tool_open' click() opens an another web page (with javascript code...). I would like to do the same (simulate mouse clic) with Qt.
[ HTML ]
[ ... ]
<ul>
<li id="tool_clear">
<div></div>
Nouvelle Configuration
</li>
<li id="tool_open" >
<div id="fileinputs">
<div></div>
</div>
Open Image
</li>
</ul>
[ ... ]@fgdevel I dont see any code which gets invoked on click of
tool_open
. For eg . the following works i.ealert
is called<script> function click(){ alert("Clicked"); } </script> <li id="list" onclick="click()">Clickable list</li>
and from Qt
QWebElement b = ui->webView->page()->mainFrame()->findFirstElement("#list"); b.evaluateJavaScript("this.click()");
-
wrote on 20 Aug 2015, 12:23 last edited by
the action is realized by this function :
[ JS ]
var clickOpen = function() { [ ... ] }but I don't know how to call this function in HTML, just clickOpen() doesn't work, even if I include the JS file in the HTML (<script src="myfile.js"></script>)
-
the action is realized by this function :
[ JS ]
var clickOpen = function() { [ ... ] }but I don't know how to call this function in HTML, just clickOpen() doesn't work, even if I include the JS file in the HTML (<script src="myfile.js"></script>)
@fgdevel Well then you need to first figure out how to call that function on click of
li
element in HTML. -
wrote on 22 Aug 2015, 00:02 last edited by
evaluateJavaScript is your friend
Exemple of code working with Jquery, replace with javascript code
QString jsToExecute += "$('#login-btn').click(); "; ui->webView_login->page()->mainFrame()->documentElement().evaluateJavaScript(jsToExecute + "; null" );
13/14