[英]how to handle element not interactable exception in selenium c#
Web Element Code: Web 元件代码:
<div class="form_field form_field--has_error sc-fBuWsC bNcPjv"
<input id="temporaryEmail" autocomplete="false" name="temporaryEmail" class="sc-hzDkRC gHYxbL" value=""/>
<label for="temporaryEmail" class="sc-jhAzac heNtmJ">
Email Address
</label>
</div>
my Driver Code我的驱动程序代码
public IWebElement emailfield => Driver.FindElement(By.XPath("//input[@id='temporaryEmail']"));
If I just use: emailfield.SendKeys(signUpCredentials.emailAddress);
如果我只是使用: emailfield.SendKeys(signUpCredentials.emailAddress);
I get error Unhandled exception: OpenQA.Selenium.ElementNotInteractableException: 'element not interactable'
我收到错误未处理的异常: OpenQA.Selenium.ElementNotInteractableException: 'element not interactable'
If I use:如果我使用:
((IJavaScriptExecutor)Driver).ExecuteScript("$('document.querySelector(#temporaryEmail'))", emailfield);
emailfield.SendKeys(signUpCredentials.emailAddress);
I get error Unhandled exception: OpenQA.Selenium.WebDriverException: 'javascript error: Unexpected token ')' (Session info: chrome=77.0.3865.120)'
我收到错误未处理的异常: OpenQA.Selenium.WebDriverException: 'javascript error: Unexpected token ')' (Session info: chrome=77.0.3865.120)'
Try using below via javascript executor尝试通过 javascript 执行器在下面使用
((IJavaScriptExecutor)Driver).ExecuteScript("document.querySelector('#temporaryEmail')", emailfield);
The issue ended up being related to the HTML on the page -- there were multiple elements found under the query //input[@id='temporaryEmail']
, so we had to write a more specific XPath to find the correct element.该问题最终与页面上的 HTML 相关——在查询//input[@id='temporaryEmail']
下找到了多个元素,因此我们必须编写更具体的 XPath 来找到正确的元素。
// wait for element to exist
// find the element
var email = Driver.FindElement(By.XPath("//input[following-sibling::label[text()='Email Address']]"));
// click the element to activate it
email.Click();
// send keys
email.SendKeys(signUpCredentials.emailAddress);
This script has successfully executed on my end, and populated field 'Email' with some text.该脚本已在我端成功执行,并在“电子邮件”字段中填充了一些文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.