我有一堆radio buttons
,並希望從標籤中獲取每個人的文本。這是我到目前爲止已經試過:我無法訪問Web元素的文本
IList<IWebElement> radioButtons = wd.FindElements(By.Name("Components[0].Entity.ComponentSubTypeId"));
foreach (IWebElement i in radioButtons)
{
Console.WriteLine(i.Text);
}
我知道,他們所得到存儲在List
,因爲當我刪除.Text
從上面,一些OpenQA.Selenium.Firefox.FirefoxWebElement
的被寫入到輸出控制檯,用它與位於頁面上的radio buttons
的數量完全匹配。
這裏是radio buttons
在頁面上的一個的HTML
:
<li class="optionListItem">
<span class="floatLeftSmallMargin componentTypeOptions">
<input class="required" id="Components_0__Entity_Entity_ComponentTypeId_PublicationGravure" name="Components[0].Entity.ComponentSubTypeId" type="radio" value="-2147380659" />
</span>
<span class="optionListItemText componentTypeOptions">
<label for="Components_0__Entity_Entity_ComponentTypeId_PublicationGravure">Publication Gravure</label>
<span class="helpButton" data-title="Publication Gravure" data-text="A printing method on a substrate that is subsequently formed into books, magazines, catalogues, brochures, directories, newspaper supplements or other types of printed materials.">
</span>
</span>
<div class="clear"></div>
</li>
但同樣,當我追加.Text
的索引我在foreach參數,沒有什麼被寫入到輸出控制檯。
這是正確的答案。謝謝LINGS! – kevin