puneet kumar
puneet kumar

Reputation: 11

Unable to locate/populate Text box in Selenium WebDriver with Java

<TD class=CuteEditorFrameContainer style="PADDING-BOTTOM: 2px; PADDING-TOP: 1px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px" height="100%" colSpan=2>
<IFRAME id=obj_oOpera class=CuteEdit style="BORDER-TOP: #c0c0c0 1px solid; HEIGHT: 100%; BORDER-RIGHT: #c0c0c0 1px solid; WIDTH: 100%; BORDER-BOTTOM: #c0c0c0 1px solid; BORDER-LEFT: #c0c0c0 1px solid; BACKGROUND-COLOR: white"  frameBorder=0>
<HTML>
<HEAD>
<STYLE>BODY {
	PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px
}
</STYLE>
</HEAD>
<BODY contentEditable=true>
</BODY>
</HTML>
</IFRAME>
<INPUT id=oOpera type=hidden name=oOpera>
</TD>

Problem I am trying to populate comment box but not able to due to following issues

-- Inspecting box takes me to code where there are no attributes - BODY contentEditable=true

JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("document.getElementsByName('obj_oOpera')[0].setAttribute('type', 'text');"); driver.findElement(By.xpath("//iframe[@id='obj_oOpera']")).clear(); driver.findElement(By.xpath("//iframe[@id='obj_oOpera']")).sendKeys("Opera");

-- When I use Attributes from IFRAME or INPUT tags throws exception Element must not be hidden/read-only or disabled

Other Methods that did not work change of frame. Java Script and usual Send Keys

PS - I am able to maually add text to Text-box

Upvotes: 0

Views: 422

Answers (1)

Waqar Nadir
Waqar Nadir

Reputation: 388

You are trying to enter a value in input but you are passing the id of the iframe. Simply replace it the input id and your issue will be solved.

JavascriptExecutor jse = (JavascriptExecutor)driver; 
jse.executeScript("document.getElementsByName('oOpera')[0].setAttribute('type', 'text');"); 
driver.findElement(By.xpath("//input[@id='oOpera']")).clear(); 
driver.findElement(By.xpath("//input[@id='oOpera']")).sendKeys("Opera");

Also, your input field is outside of Iframe and body inside Iframe has no element in it that's why it is showing empty body.

Upvotes: 1

Related Questions