gpt4 book ai didi

c# - 我无法访问 Web 元素的文本

转载 作者:行者123 更新时间:2023-11-30 14:50:14 25 4
gpt4 key购买 nike

我有一堆radio buttons,我想从每个按钮的标签中获取文本。到目前为止,这是我尝试过的:

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 的数量完全匹配。

这是页面上单选按钮之一的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 参数中的索引 i 时,没有任何内容被写入输出控制台。

最佳答案

问题是你的IList<IWebElement> radioButtons不包含标签。它只包含 input没有任何文字。所以当你做 .Text你不会看到任何文字。

IList<IWebElement> labels =  wd.FindElements(By.CssSelector(".optionListItem .optionListItemText label"));

现在迭代 labels并调用.Text ,您将看到标签名称。

关于c# - 我无法访问 Web 元素的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37307191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com