繁体   English   中英

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

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

以下是原始代码。

我想在以下文本框区域输入文本。 无法输入数据。 让我知道,如何在下面的文本框中输入文本。

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

我已输入以下代码来输入数据。

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

我还尝试了以下 Java 脚本执行器代码。

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

我错过了什么吗? 我不知道如何解决这个问题

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

如果你查看 style 属性,它的style="display:none; display as none。

您需要更改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");

你在框架中,我可以从你的 HTML 代码中看到这一点。 这意味着您只需要切换到 ireame 执行一些操作并切换回默认内容。 有多种实现方法。对于 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();

查看更多关于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