[英]How would I interact with this input box in Selenium Webdriver using Java?
I can't get it to select the input name uxCompanyName. 我无法选择输入名称uxCompanyName。 I've tried using an xpath, selenium IDE, and a by.id, name, etc. None of that worked for me.
我尝试使用xpath,Selenium IDE和by.id,名称等。这些都不适合我。 Any help would be appreciated.
任何帮助,将不胜感激。 Thanks
谢谢
My script: 我的剧本:
WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("document.getElementById('uxCompanyName').focus();");
element.findElement(By.id("uxCompanyName")).clear();
element.findElement(By.id("uxCompanyName")).sendKeys("password");
HTML: HTML:
<frameset rows="100%" frameborder="0" border="0" framespacing="0">
<frame scrolling="auto" allowtransparency="" src="CompList.aspx" noresize="noresize" name="bottom">
<html>
<head>
<body onload="document.getElementById('uxBranchID').focus();">
<form id="fm" action="CompList.aspx" method="post" name="fm">
<div>
<script type="text/javascript">
<script language="JavaScript">
<script type="text/javascript">
<link href="menu.css" type="text/css" rel="stylesheet">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadMenu_Utils_3_5_1.js" type="text/javascript">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadHelper_3_5_1.js" type="text/javascript">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadBrowser_3_5_1.js" type="text/javascript">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadMenu_Globals_3_5_1.js" type="text/javascript">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadMenu_3_5_1.js" type="text/javascript">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadMenu_Keyboard_3_5_1.js" type="text/javascript">
<script src="/secure/admin/RadControls/Menu/Scripts/3_5_1/RadImageCache_3_5_1.js" type="text/javascript">
<table id="hroMenu_tbHeader" cellspacing="0" cellpadding="0" border="0" align="Center" style="width:95%;border-collapse:collapse;">
<br>
<table width="95%" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td>
<table width="800" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<table id="tblSearch" cellspacing="1" cellpadding="2" border="0" style="background- color:Silver;width:300px;">
<tbody>
<tr class="StandardRow">
<tr class="StandardRow">
<tr class="StandardRow">
<td>
<b>Company Name:</b>
</td>
<td>
<input id="uxCompanyName" type="text" style="font-size:11px;width:150px;" maxlength="40" name="uxCompanyName">
</td>
</tr>
<tr class="StandardRow">
<tr style="background-color:WhiteSmoke;">
</tbody>
</table>
</td>
<td valign="bottom" align="right">
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<tr>
</tbody>
</table>
</form>
<div id="i1110_g" style="position: absolute; left: -500px; top: -2000px; width: 140px; height: 0px; visibility: hidden; z-index: 901;">
</body>
</html>
</frame>
</frameset>
</html>
</frame>
</frameset>
</html>
</frame>
</frameset>
Below code should work for you: 下面的代码应该为您工作:
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("bottom"));
element.findElement(By.id("uxCompanyName")).clear();
element.findElement(By.id("uxCompanyName")).sendKeys("password");
It will wait for frame, switch to it and then interacts with the element in it. 它将等待帧,切换到它,然后与其中的元素进行交互。
Selenium has trouble with frames. 硒在框架方面有麻烦。 Try
尝试
getWebDriver().switchTo().frame( getElementById( "frameId" ) );
Then grab the element 然后抓取元素
@Pradish.. The reason why you couldn't detect the WebElement with id 'uxCompanyName' was the element was not in your current frame. @Pradish ..无法检测到ID为'uxCompanyName'的WebElement的原因是该元素不在当前框架中。 If you face the same problem again then just include below line before you perform any action on the WebElement.
如果再次遇到相同的问题,则在对WebElement执行任何操作之前,只需在下面添加一行即可。 " assertTrue(driver.getPageSource().contains("uxCompanyName")); " uxCompanyName can be replaced by any unique identity of the WebElement.
“ assertTrue(driver.getPageSource()。contains(” uxCompanyName“)); ” uxCompanyName可以由WebElement的任何唯一标识替换。 If its true it will progress if not the your script will Stop at the same line.
如果为true,则脚本将在同一行停止。 Which indicates that the required WebElement is not in the frame and then you can look for the frames available on that page.
这表明所需的WebElement不在框架中,然后您可以在该页面上查找可用的框架。
Hope this helps you to figure out the reason and the solution. 希望这可以帮助您找出原因和解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.