2013-09-27 39 views
-1

我需要列出頁面上每個輸入字段的所有標題屬性與大量的輸入元素(我重新考慮碼)。它們可以在HTML中得到迴應(即,破壞網站設計並不重要)。獲取頁面上每個輸入元素的標題屬性,並使用jQuery回顯/打印它

我已經試過:

List<WebElement> elements = driver.findElements(By.tagName("input")); 
for (WebElement element : elements) { 
    if (element.getAttribute("title").val()!= '') { 
     System.out.println(element.getAttribute("title")); 
    } 
} 

在試圖列出在控制檯的元素,但我得到

Uncaught SyntaxError: Unexpected identifier

任何意見,將不勝感激。謝謝

+1

不管你已經嘗試過,甚至沒有接近Javascript,這是完全不相關的Java。 – RaphaelDDL

回答

1

你寫了Java,而不是Javascript。 They are not related, read more

不管怎麼說,這裏的JavaScript(jQuery的):

我創建一個ul ID爲nameList並將其追加到身體。

//create ul with id nameList, set bullet type and append on body 
$('<ul />').attr('id', 'nameList').css('list-style','square').appendTo('body'); 

//cache it to use on the below each 
$nameList = $('ul#nameList'); 

//each input with attribute name set 
$('input[name]').each(function(index, el) { 
    //create a li, put the current input's name (this) as a text and append to our ul 
    $('<li />').text($(this).attr('name')).appendTo($nameList); 
}); 

滾過輸入並列表::然後我上得到誰擁有name屬性,並在我的ul#nameList追加名作爲li所有輸入選擇使用.each

http://jsfiddle.net/RaphaelDDL/BQ7Mt/2/

+0

對不起 - 我的一個愚蠢的混淆︰雖然我知道Java和JavaScript是不相關的,我不熟悉Java,所以認爲這是我沒有遇到的jQuery的一些語法 - 現在我看它很明顯不。發帖時我很累 - 非常感謝jQuery,效果很好。 – Gideon

相關問題