【发布时间】:2016-06-05 22:10:56
【问题描述】:
因此,我一直在努力寻找一种通过 selenium 迭代表并从该表中收集特定值的动态方法,以创建从远程服务到本地数据标签的映射。这是我试图迭代的代码,这些长度可能会改变:
string Fee1 = driver.FindElement(By.XPath("//tr//input[@id='fees']")).GetAttribute("title");
string CCFee1 = driver.FindElement(By.XPath("//tr/td[3]/select")).GetAttribute("title");
string Fee2 = driver.FindElement(By.XPath("//tr[2]//input[@id='fees']")).GetAttribute("title");
string CCFee2 = driver.FindElement(By.XPath("//tr[2]/td[3]/select")).GetAttribute("title");
string Fee3 = driver.FindElement(By.XPath("//tr[3]//input[@id='fees']")).GetAttribute("title");
string CCFee3 = driver.FindElement(By.XPath("//tr[3]/td[3]/select")).GetAttribute("title");
string Fee4 = driver.FindElement(By.XPath("//tr[4]//input[@id='fees']")).GetAttribute("title");
string CCFee4 = driver.FindElement(By.XPath("//tr[4]/td[3]/select")).GetAttribute("title");
string Fee5 = driver.FindElement(By.XPath("//tr[5]//input[@id='fees']")).GetAttribute("title");
string CCFee5 = driver.FindElement(By.XPath("//tr[5]/td[3]/select")).GetAttribute("title");
string Fee6 = driver.FindElement(By.XPath("//tr[6]//input[@id='fees']")).GetAttribute("title");
string CCFee6 = driver.FindElement(By.XPath("//tr[6]/td[3]/select")).GetAttribute("title");
我确信有一种方法可以遍历表格,以动态方式收集值,因此只需要:
string Fee**"x"** = driver.FindElement(By.XPath("//tr//input[@id='fees']")).GetAttribute("title");
string CCFee**"x"** = driver.FindElement(By.XPath("//tr/td[3]/select")).GetAttribute("title");
其中“x”增加到表格的末尾,而且,也应该是动态的,从第二行开始,如下所示:
string Fee2 = driver.FindElement(By.XPath("//tr__[2]__//input[@id='fees']")).GetAttribute("title");
string CCFee2 = driver.FindElement(By.XPath("//tr__[2]__/td[3]/select")).GetAttribute("title");
任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: selenium