TestFx retrieve elements content of HTML in WebView

226 views Asked by At

I am writing tests in my JavaFX application using TestFx. It is going good till i access FXML elements but i am wonder how to access WebView HTML content. WebView is a major part of my application so i have to add tests for that.

Below is my HTML content sample that is use to open in WebView.

    <html> 
 <body class="mainBody" spellcheck="true" onclick="mainbodyclick()" contenteditable="false" id="idsBody"> 
  <div class="maindiv" id="maindivcontainer" oncontextmenu="maindivcontextcall(event);"> 
   <div id="regdivcontainer" contenteditable="true" style="display:block">      
    <table contenteditable="false" class="block idsTemp" onclick="tabClick(this)" id="tab0.0737569887231827"> 
     <tbody> 
      <tr> 
       <td class="header readOnly"><a name="1test468"></a><font size="3" color="blue">1</font></td> 
       <td title="block name" class="name" id="tb_name">test468</td> 
     </tbody> 
    </table>
    </div>
    </div>
    </body>
    </html>

I am trying to click on td element id="tb_name" by below code but it didn't worked

robot.clickOn("#tb_name");
robot.lookup("#webViewID > #tb_name").query();
robot.lookup("#webViewID > .web-engine #tb_name").query();
robot.lookup("#webViewID > .web-engine > .mainBody > .maindiv > .regdivcontainer #tb_name").query();

Thank you.

1

There are 1 answers

0
Nee On
Platform.runLater(new Runnable() {
            @Override
            public void run() {

                javafx.scene.web.WebView mywebview=waitsUtil.lookupById(webView,robot);

                String RegistrationID=(String) mywebview.getEngine().executeScript("document.body.getElementsByTagName('td')[0].innerHTML;");
                RID=RegistrationID.split("<br>");

            
            System.out.println(mywebview.getEngine().executeScript("document.body.innerHTML;"));

mywebview.getEngine().executeScript("document.getElementById('consent-yes').click();");
            }
        });