Pet*_*er3 1 c# selenium-webdriver
我正在尝试列出Selenium中的Web元素列表。我现在的问题是,有4个gif都可以被单击,但是都具有相同的值。我需要列出它们的清单,以便选择想要的一个。这是我的代码行
List<IWebElement> createGifs = driver.FindElements(By.XPath("//img[@ src='images/document_create.gif']"));
Run Code Online (Sandbox Code Playgroud)
我在网上看到的每个地方都可以找到合适的答案。但是我收到错误:
错误1无法将类型'System.Collections.ObjectModel.ReadOnlyCollection'隐式转换为'System.Collections.Generic.List'
有谁知道如何完成我要寻找的内容或如何解决此错误?
将其转换为ReadOnlyCollection并确保您已using System.Collections.Generic;导入
IReadOnlyCollection<IWebElement> createGifs = driver.FindElements(By.XPath("//img[@ src='images/document_create.gif']"));
Run Code Online (Sandbox Code Playgroud)
如果您确实要使用,请List使用ToList()
List<IWebElement> createGifs = driver.FindElements(By.XPath("//img[@ src='images/document_create.gif']")).ToList();
Run Code Online (Sandbox Code Playgroud)
编辑
为了澄清ISearchContext.FindElements硒的方法,ReadOnlyCollection<IWebElement>默认情况下返回。看到这个
| 归档时间: |
|
| 查看次数: |
8885 次 |
| 最近记录: |