问候!!我正在尝试识别 selenium web 驱动程序中的“文本框”以进行测试,但是我无法识别它。我尝试的每一个组合都会给我错误。阅读所有博客对我来说没有运气。但是,我能够识别文本框并能够使用带有“xpath”的 selenium IDE 输入值://input[@class='amInput55p portlet-form-input-field']。尝试将 IDE 代码转换为 Java/JUnit 4/WebDriver 不起作用。
<div id="portal-content" class="content" style="height: 99%;">
<img onerror="alert('[POP.016.0041] Please deploy wm_cafshared.war.')" style="position:absolute;z-index:-1;" alt="" src="/wm_cafshared/ui/img/blank.gif">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
<script src="/wm_cafshared/dyn/j/ui/js/controls/standard/dialog.js?l=en_US&v=100922171045" type="text/javascript">
<script type="text/javascript">
<div id="jsfwmp340233:module" class="vModule"></div>
<form id="jsfwmp340233:htmlForm1" enctype="application/x-www-form-urlencoded" action="/meta/default/amaccountmaintenance___search/0000340233?wmp_tv=%2fSearch%2fdefault.view&wmp_rt=action&wmp_tc=340233&__ns=wmp340233" method="POST" name="jsfwmp340233:htmlForm1">
<div id="jsfwmp340233:htmlForm1:breadcrumb" class="ambreadcrumb"></div>
<div id="jsfwmp340233:htmlForm1:blockPanel42" class="amRowGutterMargin2"></div>
<div id="jsfwmp340233:htmlForm1:amScreenWrapper">
<div id="jsfwmp340233:htmlForm1:blockPanel3" class="amApplicationTitleBar">
<div id="jsfwmp340233:htmlForm1:blockPanel" class="clear"></div>
<div id="jsfwmp340233:htmlForm1:content">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel2" class="amApplicationWrapper" style="height: 30px;">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel32" class="amContentWrapper">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel4" class="amRowGutterMargin6 "></div>
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel133" class="amRequiredModule">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel134" class="amTitle">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel135" class="clear"></div>
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:promptFieldID" class="amPromptFields" style="">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:promptFieldID__content">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel61" class="amRowGutterMargin2"></div>
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:requiredFieldsMsgPanel" class="amInfoMessagesPanel readonly">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel137" class="amPromptFieldColumn50p ">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel139" class="amField100p">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel140" class="amOptionalPromptLabel">
<div id="jsfwmp340233:htmlForm1:importView:htmlForm:blockPanel145" class="amInputWrapper50p">
<input id="jsfwmp340233:htmlForm1:importView:htmlForm:txtAccountNumID" class="amInput55p portlet-form-input-field" type="text" onkeypress="allowNumber(event);" onkeydown="var searchButton = 'jsfwmp340233:htmlForm1:importView:htmlForm:btnSearch'; if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) { document.getElementById(searchButton).click(); return false; }else return true;" maxlength="10" value="" name="jsfwmp340233:htmlForm1:importView:htmlForm:txtAccountNumID">
</div> - this is tag for text box
尝试了所有组合 xpath,cssSector 没有工作。-AmSearch.findElement(By.id("jsfwmp33948:htmlForm1:importView:htmlForm:txtAccountNumID")); (文本框的 Id 是动态的,预测下一个数字并在此提供)
AmSearch.findElement(By.xpath("//*[@id='portal-content']/form/div[3]/div[1]/div[1]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/input"));
AmSearch.findElement(By.cssSelector("id$=txtAccountNumID"));
AmSearch.findElement(By.xpath("//input[@class='amInput55p portlet-form-input-field']"))
对于所有出现错误的选项:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='portal-content']/form/div[3]/div[1]/div[1]/div[2]/div[2]/div[1]/div[3]/div[1]/div[2]/input"}
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element
Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_21'
Session ID: 4b36db92-7d80-43a9-aea4-309270ee77e0`enter code here`
Driver info: org.openqa.selenium.firefox.FirefoxDriver`enter code here`
请帮我解决这个问题。感谢所有帮助。