我在Visual Basic中使用C#来构建一个列表,其中包含使用XPath收集的IWebElement。我将在每个按钮上单击()。
到目前为止,我所拥有的是:
List<IWebElement> buttonlist =
driver.FindElements(By.XPath("//button[@title='Quick Apply']"));
按钮的html如下:
<button class="job_tool job_apply default" data-interview="0"
data- oneclick="0" data-contact="" data-job="0"
data-href="the url" rel="tooltip" **title="Quick Apply"**
aria-describedby="">Quick Apply</button>
所有按钮的标题都是相同的,"快速应用"。如何列出列表,然后单击所有按钮?
您可以直接迭代FindElements
的返回值:
var buttons = driver.FindElements(By.XPath("//button[@title='Quick Apply']"));
foreach (IWebElement button in buttons)
{
button.Click();
}
或者,如果你真的想用它做一个List<IWebElement>
:
var buttons = driver.FindElements(By.XPath("//button[@title='Quick Apply']"));
var list = new List<IWebElement>(buttons);