使用C#Selenium WebDriver将文本发送到具有onkeypress事件的文本框时遇到问题

编程入门 行业动态 更新时间:2024-10-28 18:33:57
本文介绍了使用C#Selenium WebDriver将文本发送到具有onkeypress事件的文本框时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有onkeypress事件的文本框,当将值输入到文本框时,该事件会执行页面渲染.在这里,我使用硒webdriver填充文本框.在填充文本框之前,我正在使用textbox.clear().因此,会调用onkeypress事件并呈现页面.因此,文本框控件已从webdriver实例中删除.

I am having a textbox which has onkeypress event which performs a page render when the value is entered to textbox. Here I am using selenium webdriver to fill the textbox. Before filling the textbox I am using textbox.clear(). So the onkeypress event get called and page gets rendered. So the textbox control is removed from webdriver instance.

onkeypress事件发生后,该元素未在网络驱动程序中列出. 这是特定文本框的源标签:

After the onkeypress event taking place, the element is not getting listed in the webdriver. This is the source tag of the particular textbox:

<input id="ctl00_ctl00_ContentPlaceHolder1_cphMainContent_wzrDREvent_txtNftnTime" class="OpCenter_DateBox" type="text" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$ContentPlaceHolder1$cphMainContent$wzrDREvent$txtNftnTime\',\'\')', 0)" name="ctl00$ctl00$ContentPlaceHolder1$cphMainContent$wzrDREvent$txtNftnTime">

您可以看到此处使用的onkeypress事件. 请提出一些有关在文本框中填充值的想法.

And you can see the onkeypress event used here. Please suggest some ideas for filling the values in textbox.

我正在使用以下代码填充我的文本框:

I am using the following code to fill my text box:

element.Clear(); element.SendKeys(value);

谢谢.

推荐答案

我使用以下JavaScript代码来克服此问题.

I have used the following JavaScript code to overcome this issue.

if (!(webDriver.GetType().FullName).Contains("IE")) { // To stop the page postback in Firefox and chrome ((IJavaScriptExecutor)webDriver).ExecuteScript("window.stop();"); }

上面的代码停止了页面加载,并且运行正常.

The above code stops the page load and it works perfectly.

但是,在Firefox 23.0及更高版本中,此JavaScript无法正常工作.否则,对于Chrome 31.0和IE 9,JavaScript可以正常工作.

However, in Firefox 23.0 and above, this JavaScript is not working. Otherwise, for Chrome 31.0 and IE 9, the JavaScript works fine.

更多推荐

使用C#Selenium WebDriver将文本发送到具有onkeypress事件的文本框时遇到问题

本文发布于:2023-11-08 10:41:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569165.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   事件   WebDriver   Selenium   onkeypress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!