问候!! 我试图在selenium web驱动程序中识别“文本框”以进行测试,但是我无法识别它。我尝试的每一个组合都给了我错误。 阅读所有博客对我来说没有运气。但是我能够识别文本框并能够使用selenium IDE输入值'xpath':// 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`
请帮助我通过这个。所有的帮助表示赞赏。
答案 0 :(得分:0)
您的cssSelector已关闭。试试这个:
By.cssSelector(input[id$='txtAccountNumID'])