使用 C# WATIN,如何获取页面上 INPUT 标记 html 元素第二次出现的值?
我尝试了很多东西,但都没有成功。调试器没有给我任何明显的方法来从返回的 4 个元素中获取元素 [1]。
Console.WriteLine(ie.Element(Find.ByClass("myclass")).GetAttributeValue("value") ) ;
// works but prints the value of the 1st of 4 input elements on the page
Console.WriteLine(ie.ElementsWithTag("input", "text").Length.ToString() );
// returns the number 4
Console.WriteLine( ie.Element(Find.ByName("login")).GetAttributeValue("value") );
// works but its not safe since its possible there might be two elements with the name login
基本上,我希望能够通过其数组索引 选择输入元素。
最佳答案
这可以帮助:
ElementCollection elementCol = ie.Elements;
elementCol = elementCol.Filter(Find.ByClass("myclass"));
string value = elemntCol[1].GetAttributeValue("value");
关于c# - 使用 C# WATIN,如何获取 INPUT 标记 html 元素的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2978243/