简体   繁体   English

如何在C#中使用IE从onclick元素中检索值

[英]How to retrieve value from the onclick element using IE in C#

I have been developing a project wherein I need to login in our internal server webpage and update values in the form and submit the data to server. 我一直在开发一个项目,我需要登录我们的内部服务器网页并更新表单中的值并将数据提交给服务器。 The main issue is, on submitting or clicking on Save button, the Internet Explorer displays a pop up button saying, "Do you need to save the data, Yes or No?". 主要问题是,在提交或单击“保存”按钮时,Internet Explorer将显示一个弹出按钮,显示“您是否需要保存数据,是还是否?”。 Upon selecting yes, the data gets submitted and I get another pop up button displaying, "Data submitted". 选择“是”后,数据将被提交,然后我会看到另一个弹出按钮,显示“数据已提交”。 However, in case there is duplicate data, it shows a Validation error pop up showing, data already exists.I'm not able to capture the value returned by the method. 但是,如果有重复的数据,则会弹出验证错误提示,表明数据已经存在,我无法捕获该方法返回的值。

Since it is a internal server link and I can't post the screenshot or link from my company desktop, I'm sharing the bits of below HTML code from Internet Explorer. 由于它是内部服务器链接,并且无法发布公司桌面上的屏幕快照或链接,因此, 我将共享Internet Explorer中以下HTML代码的部分内容。

<a id= "saveButton" onclick="submitter('Save'); return false;" href="" shape= "">

C# code C#代码

InternetExplorerMedium IE = new InternetExplorerMedium();
HTMLDocument hdoc = new HTMLDocument();
IE.visible = true;
IE.Navigate("Internal web server page");

After updating all the values in form, navigating to the Save button of the form using the below code 更新表单中的所有值后,使用以下代码导航至表单的“保存”按钮

hdoc.all.item("saveButton").click();

So I need to get the return value of onclick element ie is it true or false. 所以我需要获取onclick元素返回值,即它是true还是false。 I have tried hdoc.parentWindow.execscript("submitter('Save'); return false;","javascript"); 我已经尝试过hdoc.parentWindow.execscript("submitter('Save'); return false;","javascript"); but it did nothing. 但是什么也没做。 It seems InvokeScript doesnt work with IE. 看来InvokeScript用于IE。 Has anyone ever worked on such query? 有没有人做过这样的查询?

Note - InternetExplorerMedium is the only way by which the internal server webpage is getting opened. 注意 InternetExplorerMedium是打开内部服务器网页的唯一方法。 InternetExplorer class was not of any help while loading the page. 加载页面时, InternetExplorer类没有任何帮助。

<form name="myform" onsubmit="return submitter(event);" action="/account/login.php">
<label>name:<br/>
<input name="txtname" id="txtname" />
</label>
<label>secret:<br/>
<input type="password"/>
</label>
<input type="submit" value="Login"/>
<input type="reset" value="Reset"/>
</form>

<script type="javascript/text">
function submitter(evt){
// return true or false to allow the form to be submitted.
// do your field validations in this function.
}
</script>

To help you we need to see the markup and scripting of the internal web page you are trying to automate from C#.... It appears that that web page is incorrectly designed (does not use the above design pattern)...the process flow is 1. Load web page with a form on it. 为了帮助您,我们需要查看您尝试从C#自动执行的内部网页的标记和脚本。...看来该网页的设计不正确(不使用上述设计模式)...该过程流程是1.加载带有表单的网页。 2. User enters data into a form. 2.用户将数据输入表单。 3. User clicks the submit button for the form... this triggers the form onsubmit event handler (submitter) which should then validate the data entered. 3.用户单击表单的提交按钮...这将触发表单onsubmit事件处理程序(submitter),该事件处理程序应随后验证输入的数据。 If its valid submitter returns true and the form data is submitted to the server (action attribute of the form). 如果其有效的提交者返回true,并且表单数据已提交到服务器(表单的action属性)。 If the data is not valid the submitter function return false, cancelling the onsubmit event handler. 如果数据无效,则Submitter函数返回false,从而取消onsubmit事件处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM