Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java/Selenium代码,用于单击框架中表单中的按钮_Java_Selenium - Fatal编程技术网

Java/Selenium代码,用于单击框架中表单中的按钮

Java/Selenium代码,用于单击框架中表单中的按钮,java,selenium,Java,Selenium,由于对Selenium和Java都是新手,我正在尝试弄清楚如何登录本地intranet上的web应用程序(评估Selenium和SilkTest) 您可以在下面找到登录表单的html代码: <head> <frameset id="myFrameSet" onload="initPage()" framespacing="0" rows="*,0"> <frame id="ContentFrame" frameborder="NO" noresize="NORESI

由于对Selenium和Java都是新手,我正在尝试弄清楚如何登录本地intranet上的web应用程序(评估Selenium和SilkTest)

您可以在下面找到登录表单的html代码:

<head>
<frameset id="myFrameSet" onload="initPage()" framespacing="0" rows="*,0">
<frame id="ContentFrame" frameborder="NO" noresize="NORESIZE" src="/webapp/servlet/frameserver?name=temp\101023065f3049414ff56b2fb27fb9_10102306576e36914ff484fb3e7f90_content261.htm&encoding=UTF-8">
<html>
<head>
<body background="../images/ingbgrnd.gif">
<form id="inputForm" target="_parent" onsubmit="return(onSubmit());" method="post" action="pageserver">
<input type="hidden" value="ACTION_NEXT" name="action">
<div align="left">
<center> </center>
<table width="578" cellspacing="0" cellpadding="3" border="0">
<tbody>
<tr>
<td width="6" align="left"> </td>
<td width="121" align="left">
<label class="clsform" for="SOME-USER-ID">Name:</label>
</td>
<td width="187" align="left">
<input type="text" value="" tabindex="1" size="15" name="SOME-USER-ID" mandatory="yes">
</td>
</tr>
<tr>
<td width="187" align="left">
<input type="password" value="" tabindex="2" size="15" name="SOME-USER-PSWD-TXT" mandatory="yes">
</td>
</tr>
<tr>
<tr>
<td width="6" align="left"> </td>
<td width="316" align="left" colspan="2">
<p align="center">
<input width="143" type="image" border="0" height="38" tabindex="4" src="../english/images/submit.gif" alt="Submit">
</p>
</td>
</tr>
</tbody>
</table>
</div>
我已经知道如何切换到框架,在名称和密码字段中输入值,但无论我尝试单击“提交”按钮的方法是什么,它都不起作用(错误:没有这样的元素)

我的代码:

driver.get("http://svr/index.html");
driver.manage().window().maximize();        
driver.findElement(By.linkText("English Sign On")).click();
driver.switchTo().frame("ContentFrame");
driver.findElement(By.name("SOME-USER-ID")).sendKeys("user");
driver.findElement(By.name("SOME-USER-PSWD-TXT")).sendKeys("password");
driver.findElement(By.partialLinkText("Submit")).click();

这是一个仅在IE8上工作的应用程序,因此没有firebug选项(尝试了firebug Lite,但也不起作用,尽管它与其他一些外部站点一起工作)。如果您能给我一个建议,告诉我“提交”按钮(上面代码中的最后一行)应该使用哪种定位器,我将不胜感激。

我认为.partialLinkText(“提交”)的
与您的

<input width="143" type="image" border="0" height="38" tabindex="4" src="../english/images/submit.gif" alt="Submit">

请显示
iframe
和当前正在执行的代码。完成。添加了框架线和我的代码。当你发布HTML时,请花一分钟的时间使用一个美化器来正确格式化它。它使阅读更容易,使你的问题更有可能得到回答。谢谢谢谢你的建议,杰夫!感谢您提供文档的链接!这就是我要学会正确使用的东西。你的解决方案奏效了。再次感谢!美好的我不知道。您还可以使用
driver.findElement(通过.cssSelector(“输入[alt='Submit']”),单击()。啊,很酷,所以按属性选择是有效的,我会记住:D
<input width="143" type="image" border="0" height="38" tabindex="4" src="../english/images/submit.gif" alt="Submit">
driver.findElement(By.name("SOME-USER-PSWD-TXT")).submit();