0

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

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering, Surya. I got it to work by using the .switchto command in my reply to Kyle.
Okay. Good. "frameToBeAvailableAndSwitchToIt" will also do the same thing, it will wait for the frame to load and then it will switch to it. Its more reliable way of switching to frame, as some time frames will take time to load fully.
0

Selenium has trouble with frames. Try

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

Then grab the element

2 Comments

Is this the full script or does it need to be added onto something?
Thanks, Kyle. It worked with some slight modification. I'm not sure what your block of code is written in but I used the following: driver.switchTo().frame("bottom"); driver.findElement(By.xpath("//input[@name='uxCompanyName']")).sendKeys("moneta");
0

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

3 Comments

Thanks, Rupesh! This is a neat little check.
@PradishSuhiet : If you think this answer is informative to your question then please upvote it.
I think I need more reps to upvote you. I'll be sure to come back once I have this ability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.