Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过Selenium和c将文本发送到文本角度标记中的输入标记#_C#_Angular_Selenium_Selenium Webdriver_Xpath - Fatal编程技术网

C# 如何通过Selenium和c将文本发送到文本角度标记中的输入标记#

C# 如何通过Selenium和c将文本发送到文本角度标记中的输入标记#,c#,angular,selenium,selenium-webdriver,xpath,C#,Angular,Selenium,Selenium Webdriver,Xpath,下面是我试图在其中发布selenium测试的代码…下面是我正在使用的代码 IWebElement xxvalue = webElement.FindElement(By.Id("emailMessageContent")); xxvalue.SendKeys("This is only a test"); 我尝试了其中的许多元素来查找测试消息并将其发送给,但都没有成功。输入是“隐藏的”…因此它无法找到该字段并输入它。。。有没有人遇到过这个问题,可以告诉我如何将信息发布到文本区域或输入?等等

下面是我试图在其中发布selenium测试的代码…下面是我正在使用的代码

 IWebElement xxvalue = webElement.FindElement(By.Id("emailMessageContent"));
 xxvalue.SendKeys("This is only a test");
我尝试了其中的许多元素来查找测试消息并将其发送给,但都没有成功。输入是“隐藏的”…因此它无法找到该字段并输入它。。。有没有人遇到过这个问题,可以告诉我如何将信息发布到文本区域或输入?等等


电子邮件内容

如果元素被隐藏,请尝试以下操作:

IWebElement xxvalue =  webElement.FindElement(By.Id("emailMessageContent"));

IJavascriptExecutor JE = (IJavascriptExecutor)driver; //your webdriver instance here

//here you define the string to make the element visible
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";

JE.ExecuteScript(js, xxvalue);

xxvalue.SendKeys("This is only a test");

当您想向
标记发送文本时,可以使用以下代码块:

IWebElement xxvalue = driver.FindElement(By.XPath("//textarea[@class='ng-pristine ng-untouched ng-valid ng-scope ta-bind ta-html ta-editor form-control ng-hide']/input[@name='emailMessageContent']"));
String js = "arguments[0].style.display='block'; arguments[0].type='text';";
((IJavascriptExecutor) driver).ExecuteScript(js, xxvalue);
xxvalue.SendKeys("This is only a test");
IWebElement xxvalue = driver.FindElement(By.XPath("//textarea[@class='ng-pristine ng-untouched ng-valid ng-scope ta-bind ta-html ta-editor form-control ng-hide']/input[@name='emailMessageContent']"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].removeAttribute('style')", xxvalue)
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].type='text';", xxvalue);
xxvalue.SendKeys("This is only a test");
注意:我的答案中的WebDriver实例是driver

或者,您也可以尝试以下代码块:

IWebElement xxvalue = driver.FindElement(By.XPath("//textarea[@class='ng-pristine ng-untouched ng-valid ng-scope ta-bind ta-html ta-editor form-control ng-hide']/input[@name='emailMessageContent']"));
String js = "arguments[0].style.display='block'; arguments[0].type='text';";
((IJavascriptExecutor) driver).ExecuteScript(js, xxvalue);
xxvalue.SendKeys("This is only a test");
IWebElement xxvalue = driver.FindElement(By.XPath("//textarea[@class='ng-pristine ng-untouched ng-valid ng-scope ta-bind ta-html ta-editor form-control ng-hide']/input[@name='emailMessageContent']"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].removeAttribute('style')", xxvalue)
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].type='text';", xxvalue);
xxvalue.SendKeys("This is only a test");

我将光标放在字段上,但当我尝试发送键时,它说它无法聚焦在该对象上,这很奇怪……但我遇到了“动作”的Selenium命令。我用过这个,它对我有用

            IWebElement messageContent = Driver.Instance.FindElement(By.Id("emailMessageContent"));
            Actions actions = new Actions(Driver.Instance);
            actions.MoveToElement(messageContent);
            actions.Click();
            actions.SendKeys("This is a test");
            actions.Build().Perform();

不是说我介意-1…但是为什么?是的…这似乎是你们两人的解决方案…我对selenium很陌生,这是我第一次遇到JavaScriptExecutor,我感谢你们两位向我指出这一点。希望它现在可以工作。它说元素仍然不可见…我也应该做任何类型的javascript重载/引用吗?它仍然说元素不可见。当检查该webelement的值时,它说enabled=true,但displayed=false…@GregP检查我的更新答案并让我知道结果。它说该元素仍然不可见…我也应该执行任何类型的javascript重载/引用吗?