2014-09-04 129 views
0

使用Selenium Web驱动程序我如何访问具有动态ID且没有名称但具有submitName属性的输入文本元素。该文件有多个元素,我需要访问4个元素。访问元素submitName selenium webdriver

<input class="mandy" id="ms__id7" submitName="intYPoliceForce"/> 

这里是我迄今为止尝试过

返回Nothing

Driver.FindElementByClassName("mandy").GetAttribute("submitName") 

不返回webElements的名单?

Driver.FindElement(By.TagName("input")) 

回答

1

尝试水木清华这样的:

driver.FindElement(By.Css("input[submitName='intYPoliceForce']")); 
//if you want to access all items with class mandy 
var inputs = driver.FindElements(By.Css(".mandy")); 
inputs[0].click() //etc... 
//or using xpath analog to access element using beginning of that id 
driver.FindElement(By.Css("input[id^='ms__id']")) 
0

我无法管理使用submitName直接,我不明白为什么submitName属性不能访问可能是涉及到jQuery来访问元素不是JavaScript?但可以访问其他属性。

我去通过XPath来访问这两个输入框

/input[@class='mandy' and starts-with(@id, 'ms__id')][1] 
/input[@class='mandy' and starts-with(@id, 'ms__id')][2] 
+0

这是我做到了....新选择(driver.findElement(By.xpath(“//组合框[@ ID =” intYPoliceForce'] //选择“)))。getFirstSelectedOption() – 2016-12-07 17:09:55