明顯的問題是,當我嘗試將值設置爲輸入,硒返回以下錯誤創建: RuntimeError:元素是不可見的,所以可能無法進行交互元素與XSLT模板不受硒
無論如何,輸入完全可見。在這個測試中,我使用的是Firefox,因爲是正確加載應用程序的瀏覽器。
我無法更改應用程序代碼,應用程序有很多遺留代碼,但我重新創建了可以看到問題的最簡單示例。
您是否知道任何解決方法而無需修改應用程序代碼?
我使用webdriverio:
this.browser
.url('http://localhost/main.xml')
.setValue('[name=inputId]', 'aaaaaaaa')
.close()
.then(callback)
的main.xml內容:
<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="main.xsl" ?>
<CONTEXTO></CONTEXTO>
main.xsl內容:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1"/>
<xsl:include href="helper.xsl"/>
<xsl:template match="CONTEXTO">
<html>
<head>
<title>Test main</title>
<style>
* { margin:0; }
form { position: absolute; }
input { border: 1px black solid; }
</style>
</head>
<body>
<form name="" action="" method="POST">
<label for="inputId">inputId
<input type="text" name="inputId" id="inputId" value="" />
</label>
</form>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
helper.xsl內容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<script></script>
<xsl:apply-templates select="CONTEXTO"/>
</xsl:template>
</xsl:stylesheet>
感謝@Abel:您還可以通過執行以下代碼在Firefox的調試窗口重現XSL問題。我可以找到使用硒的元素,但不能識別爲可見。使用webdriver.io的selectorExecute方法它返回這個錯誤:RuntimeError:等待doc.body失敗。我在Selenium Developers小組發現了一個[關於這個問題](https://groups.google.com/forum/#!msg/selenium-developer-activity/OCCabUAE4Vw/VN7NyREIHk8J),它似乎是Firefox中的一個bug當xml文檔格式不正確時,在瀏覽器中執行js。 – atena
@atena,如果XML文檔格式不正確,那麼XSLT甚至無法正常運行。如果您在沒有Selenium的情況下加載文檔,它是否正確渲染?如果檢查源代碼,您將看到呈現的XML,是否格式正確並且有效(可能是處理器啓動,並在發現非法內容時中斷,這是XSLT允許且符合標準的方法) – Abel
是的@阿貝爾,應用程序是舊的內部網的一部分,它只是在一些Firefox和IE版本。我認爲問題是html標籤之前包含的腳本標籤,但這是我無法改變的。 – atena