我尝试从输入提交按钮获取ID。确认它正确之后,我想单击它。...但是找不到提交类型的输入。 我收到NoSuchElementException。
提前谢谢大家:-)
我的HTML代码
<html>
<body>
<form name="aspnetForm" method="post" action="./river.aspx" id="aspnetForm">
<!--CONTENT START-->
<table width="100%" style="text-align: center">
<tbody>
<tr>
<td style="vertical-align: top">
<span class="CHeading">Choose a river in Stockholm:</span><br>
<input type="submit" name="ctl00$BodyContent$btnChooseRiver00" value="River 00" id="ctl00_BodyContent_btnChooseRiver00" class="CButtonLarge">
<span><br></span>
<input type="submit" name="ctl00$BodyContent$btnChooseRiver01" value="River 01" id="ctl00_BodyContent_btnChooseRiver01" class="CButtonLarge">
</td>
<td style="vertical-align: top">
<span class="CHeading">Choose a river in Solna:</span><br>
<input type="submit" name="ctl00$BodyContent$btnChooseRiver10" value="River 10" id="ctl00_BodyContent_btnChooseRiver10" class="CButtonLarge">
<span><br></span>
<input type="submit" name="ctl00$BodyContent$btnChooseRiver11" value="River 11" id="ctl00_BodyContent_btnChooseRiver11" class="CButtonLarge">
<span><br></span>
<input type="submit" name="ctl00$BodyContent$btnChooseRiver12" value="River 12" id="ctl00_BodyContent_btnChooseRiver12" class="CButtonLarge">
<span><br></span>
<input type="submit" name="ctl00$BodyContent$btnChooseRiver13" value="River 13" id="ctl00_BodyContent_btnChooseRiver13" class="CButtonLarge">
</td>
</tr>
</tbody>
</table>
</form>
</body>
我的python代码:
try:
trInTable = driver.find_element_by_css_selector("#aspnetForm > table > tbody > tr")
twoTdWithData = trInTable.find_elements_by_css_selector('td')
# I get 2 TD in next step
print(len(twoTdWithData))
#loop the 2 TD
for td in twoTdWithData:
oneChoose = td.find_element_by_css_selector("input[type='submit']")
idInButton = oneChoose.get_attribute("id")
TimeoutException除外: print('TimeoutException') 除了NoSuchElementException: print('NoSuchElementException')
答案 0 :(得分:0)
欢迎来到SO。 这是代码。
form = driver.find_element_by_id('aspnetForm')
submitBtns = form.find_elements_by_xpath("//table//tr//td/input[@type='submit']")
for submitBtn in submitBtns:
print submitBtn.get_attribute("id")