Kamal
Kamal

Reputation: 21

Not able to enter text in the text area using Selenium Web Driver C#

Following is the origin code.

I want to enter text in the following text box area. Not able to enter the data. Let me know, how can I enter text in the below text box.

    <td id="ctl00_cRight_ucSMS_redSMSBodyCenter" class="reContentCell" style="height:100%;">
    <label for="ctl00_cRight_ucSMS_redSMSBodyContentHiddenTextarea" style="display:none;">
RadEditor hidden textarea
</label>
    <textarea id="ctl00_cRight_ucSMS_redSMSBodyContentHiddenTextarea" name="ctl00$cRight$ucSMS$redSMSBody" rows="4" cols="20" style="display:none;">
    </textarea>
    <iframe frameborder="0" src="javascript:'<html></html>';id="ctl00_cRight_ucSMS_redSMSBody_contentIframe" title="Rich text editor with ID ctl00_cRight_ucSMS_redSMSBody" style="width: 100%; height: 218.009px; margin: 0px; padding: 0px;">
    </iframe></td>

I have entered the below code to enter the data.

IWebElement userid = FamosDriver.WebDriver.FindElement(By.Id("ctl00_cRight_ucSMS_redSMSBodyCenter"));
                userid.SendKeys("Test");

Also I have tried the following Java script executor code.

IJavaScriptExecutor jst = FamosDriver.WebDriver as IJavaScriptExecutor;
         jst.executeScript("document.getElementById('ctl00_cRight_ucSMS_redSMSBodyCenter').value='testuser'"); 

Am I missing something? I dont know how to fix this

Upvotes: 1

Views: 551

Answers (2)

KunduK
KunduK

Reputation: 33384

<textarea id="ctl00_cRight_ucSMS_redSMSBodyContentHiddenTextarea" name="ctl00$cRight$ucSMS$redSMSBody" rows="4" cols="20" style="display:none;">
    </textarea>

If you look into style attribute it is having style="display:none; display as none.

You need to change the attribute of the textarea and then use send_keys() Use java script executor to set the attribute.

IWebElement userid = FamosDriver.WebDriver.FindElement(By.Id("ctl00_cRight_ucSMS_redSMSBodyCenter"));
IJavaScriptExecutor js =FamosDriver.WebDriver as IJavaScriptExecutor;;
js.executeScript("arguments[0].style='display: block;'", userid);
userid.SendKeys("Test");

Upvotes: 2

Gaj Julije
Gaj Julije

Reputation: 2183

You are in frame as I can see this from your HTML code. That means that you just need to switch to the ifreame do some action and switch back to default content. There are multiple ways to implement it.For C# it will look like:

//Use one of these 4 options
driver.SwitchTo().Frame(frame-id);
driver.SwitchTo().Frame("frame-name");
 
/* weblocator can be XPath, CssSelector, Id, Name, etc. */
driver.SwitchTo().Frame(driver.FindElement(By.weblocator("web-locator-property")));
//////YOUR ACTION
driver.SwitchTo().DefaultContent();

See more on https://www.lambdatest.com/blog/handling-frames-and-iframes-selenium-c-sharp/

Upvotes: 0

Related Questions