如何解决尝试通过Selenium清除文本时发生InvalidElementStateException
按照该HTML已经共享了<input>
与元素placeholder
属性 为 是 角
元素,因为你必须发送短信,你必须诱使 webdriverwait 的 元素可以点击 如下:
IWebElement myElem = new webdriverwait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='ng-valid md-input ng-not-empty md-autofocus ng-touched ng-dirty ng-valid-parse' and starts-with(@id,'input_') and @placeholder='Removal reason']")));
myElem.Click();
myElem.Clear();
myElem.SendKeys("Automated Test - Delete Field");
解决方法
我正在测试的Web应用程序在删除记录时需要确认。
我创建了一个测试,以输入删除此记录的有效理由。
执行此操作的代码如下:
DeleteFieldButton.
Click();
WaitMethods.WaitForElementToBeDisplayed(RemovalReason,20);
RemovalReason
.Click();
RemovalReason
.Clear();
RemovalReason
.SendKeys("Automated Test - Delete Field");
文本框的XPath如下:
private Label RemovalReason = new Label(By.XPath("//*[@placeholder = 'Removal reason']"));
每当运行测试时,都会返回以下异常。
OpenQA.Selenium.InvalidElementStateException
HResult=0x80131500
Message=Cannot clear By.XPath: //*[@placeholder = 'Removal reason'] as it is
not declared as a writable text element
Source=web
StackTrace:
at web.Elements.Common.Element.Clear()
at Daera.Efs.Test.E2e.PageObjects.ApplicationSummary.DeleteField(String
FieldIDToDelete) in
C:\Code\Local\WebApp.E2e\PageObjects\ApplicationSummary.cs:line 280
at Test.E2e.Tests.ApplicationSummaryTest.Delete_Wider_General_Field_From_Application_Summary() in C:\Code\Local\WebApp.E2e\Tests\ApplicationSummaryTest.cs:line 45
以下是Web应用程序上元素的HTML:
<input ng-keypress="dialog.keypress($event)" md-autofocus="" ng-model="dialog.result" placeholder="Removal reason" class="ng-valid md-input ng-not-empty md-autofocus ng-touched ng-dirty ng-valid-parse" aria-label="Removal reason" id="input_22" aria-invalid="false" style="">
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。