Jason Krept
Jason Krept

Reputation: 165

How would I interact with this input box in Selenium Webdriver using Java?

I can't get it to select the input name uxCompanyName. I've tried using an xpath, selenium IDE, and a by.id, name, etc. None of that worked for me. 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:

<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>

Upvotes: 0

Views: 1185

Answers (3)

Rupesh Shinde
Rupesh Shinde

Reputation: 1956

@Pradish.. The reason why you couldn't detect the WebElement with id 'uxCompanyName' was the element was not in your current frame. If you face the same problem again then just include below line before you perform any action on the WebElement. "assertTrue(driver.getPageSource().contains("uxCompanyName"));" uxCompanyName can be replaced by any unique identity of the WebElement. If its true it will progress if not the your script will Stop at the same line. Which indicates that the required WebElement is not in the frame and then you can look for the frames available on that page.

Hope this helps you to figure out the reason and the solution.

Upvotes: 0

Surya
Surya

Reputation: 4536

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.

Upvotes: 1

Kyle
Kyle

Reputation: 59

Selenium has trouble with frames. Try

getWebDriver().switchTo().frame( getElementById( "frameId" ) );

Then grab the element

Upvotes: 0

Related Questions