我正在嘗試爲使用jstree的jsp頁面爲java應用程序編寫一些硒測試。儘管我有很多基本測試需要遵循,但我還沒有做太多的工作。硒測試 - 單擊以展開jstree節點
本質上,id是自動生成的,因此我使用xpath來定位特定的興趣點。在頁面上我希望選擇的葉子是隱藏的(所以不能用於測試)。因此,我的單元測試的第一項任務是擴展一個特定的鏈接,因此子節點已呈現並可用於我的實際測試。似乎對這個關鍵的元素是一個i標籤。
編輯清晰度
如果你看看https://www.jstree.com/demo/我基本上是試圖去建築節點下在Java Selenium測試LED(所以如果你看看源,當你打開網頁有沒有提及Building,但是當你打開LED節點時,就會呈現html)。我希望這是有道理的?!
<li role="treeitem" aria-selected="false" aria-level="2" aria-labelledby="M[randomnumber]_anchor" aria-expanded="false" id=" M[randomnumber]" class="jstree-node treeNodeTextParentLevel3 jstree-closed">
<i class="jstree-icon jstree-ocl" role="presentation"></i>
<a class="jstree-anchor" href="#" tabindex="-1" id=" M[randomnumber]_anchor ">
<i class="jstree-icon jstree-checkbox" role="presentation"></i>
<i class="jstree-icon jstree-themeicon" role="presentation"></i>
Visible leaf text</a>
</li>
使用Chrome開發人員工具告訴我,
<i class="jstree-icon jstree-ocl" role="presentation"></i>
是你需要點擊展開子節點的元素。
這臺
aria-expanded="true"
和
class="jstree-node jstree-open"
所以我用2種的方法來此
1)如果我嘗試
driverWait.until(ExpectedConditions.elementToBeClickable(
By.xpath("//aside/div/div/ul/li[@id=’knownId] ']/ul/li[contains(@id,'M')]/i"))).click();
我得到一個錯誤
Element <i class="jstree-icon jstree-ocl" role="presentation"></i> is
> not clickable at point
這對i標籤看起來可能公平嗎?
2)於是,我就直接通過改變屬性
WebElement element = driver.findElement(By.xpath("//aside/div/div/ul/li[@id=’knownId']/ul/li[contains(@id,'M')]"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('aria-expanded',arguments[1]);", element, "true");
js.executeScript("arguments[0].setAttribute('class',arguments[1]);", element, "jstree-node jstree-open");
但在這種情況下,樹葉不擴大做到這一點(雖然如果我做一個element.getAttribute(「詠歎調擴展」) ;之後例如屬性已經更新,它似乎在被測試的頁面上什麼都不做),所以我不能選擇我真正想測試的子項目。
任何人都可以指出我正確的方向嗎?
你能分享網站的網址嗎? –
對不起,它還沒有生活,但如果你看看https://www.jstree.com/demo/我基本上試圖到達LED下的建築節點在一個Java硒測試(所以如果你看你的來源,當你打開頁面沒有提及Building,但是當你打開LED節點時,html會被渲染)。其實我會在問題中加上這個註釋。 – gringogordo