Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 自动滚动到HTML中的元素_Java_Html_Xml_Xslt - Fatal编程技术网

Java 自动滚动到HTML中的元素

Java 自动滚动到HTML中的元素,java,html,xml,xslt,Java,Html,Xml,Xslt,我有一个包含大量测试数据的XML。我使用XSLT在浏览器中用HTML表示这些数据。每个测试都有一个包含测试步骤的表。每次运行测试时,表都会更新表中的数据(如果通过或未通过)。然后浏览器重新加载页面。我希望它总是跳到它目前正在工作的桌子上。我怎样才能做到这一点?我的XSLT文件: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&

我有一个包含大量测试数据的XML。我使用XSLT在浏览器中用HTML表示这些数据。每个测试都有一个包含测试步骤的表。每次运行测试时,表都会更新表中的数据(如果通过或未通过)。然后浏览器重新加载页面。我希望它总是跳到它目前正在工作的桌子上。我怎样才能做到这一点?我的XSLT文件:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
  <head>
  <script type="text/javascript">


    var testnum = 0;
     if(document.cookie.indexOf('testnum=') !== -1) {

     testnum = document.cookie.split('testnum=')[1].split(';')[0];

    document.cookie = 'testnum=' + testnum + 1 + ';expires=Sat, 14 May 2015 18:00:00      GMT";';
   } else {

      document.cookie = 'testnum=1;expires=Sat, 14 May 2015 18:00:00 GMT";';
   }

var w = $(window);
var row = $('#test').find('tr').eq( testnum );

if (row.length){
    w.scrollTop( row.offset().top - (w.height()/2) );
}

</script>

  <title>HMI Automotive Testing</title>
  <link rel="stylesheet" type="text/css" href="report.css" />

  </head>

  <body>

    <center>
    <h1>HMI Automotive Testing</h1>

      <br></br>
      <div style="height:650px;width:824px;border:1px solid;overflow:auto;">

            <table border="1" id ="test">
            <xsl:for-each select= "TestSuite/TestCase">

                        <tr>
                        <b><xsl:value-of select="@name"/></b>

                        </tr>

                        <xsl:for-each select="Verification|Command">
                                <tr>
                                <xsl:choose>
                                        <xsl:when test="contains(name() , 'Verification')">

                                        <td>Verification <xsl:value-of select="@type"/></td>
                                        <td><xsl:value-of select="@status"/></td>
                                </xsl:when>
                                <xsl:when  test="contains(name() , 'Command')">
                                        <td>Command <xsl:value-of select="@type"/></td>
                                        <td><xsl:value-of select="@status"/></td>
                                </xsl:when>
                                </xsl:choose>

                                </tr>


                        </xsl:for-each>

              </xsl:for-each>
              </table>  
            </div>
      </center>



  </body>
  </html>

</xsl:template>

</xsl:stylesheet> 

var-testnum=0;
if(document.cookie.indexOf('testnum=')!=-1){
testnum=document.cookie.split('testnum=')[1]。split(';')[0];
document.cookie='testnum='+testnum+1+';expires=Sat,2015年5月14日格林威治标准时间18:00:00“;
}否则{
document.cookie='testnum=1;expires=Sat,2015年5月14日18:00:00 GMT';
}
var w=$(窗口);
var row=$('#test').find('tr').eq(testnum);
if(行长){
w、 滚动顶部(row.offset().top-(w.height()/2));
}
HMI自动测试
HMI自动测试


验证 命令
使用
id
属性

<table id="result1">
...
</table>

...

然后,如果您将页面重定向到
,您的_page.html#result1
浏览器将滚动到此表。

您需要引入一些状态,以便浏览器可以知道当前正在进行的测试。您可以通过几种不同的方式执行此操作:

统一资源定位地址 如果您可以在每次运行测试时向URL添加一个参数,那么您应该按照@psur所说的做

曲奇饼 使用Cookie存储当前测试编号

当XSLT输出HTML页面时,让它在顶部也输出一些js。这需要检查cookie是否存在,并在每次加载页面时增加它的值,然后在HTML中滚动到该位置。大概是这样的:

<script type="text/javascript">
//<![CDATA[

var testnum = 0;
if(document.cookie.indexOf('testnum=') !== -1) {
    // Cookie already exists, this isn't the first test, read the testnum
    testnum = document.cookie.split('testnum=')[1].split(';')[0];
    // write to next testnum back to the cookie for next time.
    document.cookie = 'testnum=' + testnum + 1 + ';expires=Sat, 14 May 2015 18:00:00 GMT";';
} else {
    // No cookie, must be first test
    document.cookie = 'testnum=1;expires=Sat, 14 May 2015 18:00:00 GMT";';
}
// scroll to the correct test table
location.hash = '#' + testnum;

//]]>
</script>

//

除了这些事情之一,您还需要执行@psur所说的操作,即为每个表添加一个id,以便浏览器可以滚动到该表。我建议只使用以下号码:

<table id="1">
...
</table>

...

问题是我没有调用URL。我正在使用一个WebDriver和Selenium,它不断刷新以更新我的表。每次更新时,我都希望它滚动到正在更新的表格。嗨,听起来很好。问题是这些表是使用XSLT创建的。我想我可以使用XSLT设置一个属性,但我也可以增加一个数字吗?是的,可以使用xsl:variable或xsl:number,请参见:好的,我现在有一个大表,但滚动仍然不起作用。我的XSLT文件现在包含在问题中。桌子上的水溢出来是个问题吗?我不这么认为。cookies部分工作正常并且testnum变量增加了吗?如果您发布一段XML,我可以自己测试它。