简体   繁体   English

使用 Selenium Web 驱动程序 C# 无法在文本区域中输入文本

[英]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.我还尝试了以下 Java 脚本执行器代码。

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我不知道如何解决这个问题

<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.如果你查看 style 属性,它的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.您需要更改textarea的属性,然后使用send_keys()使用 java 脚本执行器来设置属性。

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");

You are in frame as I can see this from your HTML code.你在框架中,我可以从你的 HTML 代码中看到这一点。 That means that you just need to switch to the ifreame do some action and switch back to default content.这意味着您只需要切换到 ireame 执行一些操作并切换回默认内容。 There are multiple ways to implement it.For C# it will look like:有多种实现方法。对于 C#,它看起来像:

//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/查看更多关于https://www.lambdatest.com/blog/handling-frames-and-iframes-selenium-c-sharp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM