在WebBrowser C#中执行JS函数 [英] Execute a JS function in WebBrowser C#

查看:76
本文介绍了在WebBrowser C#中执行JS函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何在网站上自动执行任务。我有一个html代码段,其中包含一个JavaScript代码,我希望使用WebBrowser Control以编程方式调用。我正在使用IE11进行仿真。我无法编辑网站源代码。

如何调用JS代码。



I am learning how to automate tasks on Websites.I have an html snippet which contains a JavaScript Code which i wish to invoke programmatically using WebBrowser Control.I am using IE11 for Emulation.I cannot edit the Website Source.
How to invoke the JS Code.

<a style="removed: auto ! important;" id="13185-SL-CK-0" href="javascript:jpBook($('#13185-SL-CK-0'),'13185','SDAH','DBG','24-10-2015','SL','CK',3,false);" tabindex="1">Book Now</a>





在我粘贴href i的内容时,在我的MozillaBrowser控制台中获得所需的结果(执行JS)。但是在WinForms中。我试过了





In my MozillaBrowser Console when i paste the content of href i get the desired results(the JS is executed).But in WinForms. I have tried

webBrowser1.Navigate("javascript:jpBook($('#13185-SL-CK-0'),'13185','SDAH','DBG','24-10-2015','SL','CK',3,false);");







webBrowser1.Document.InvokeScript("javascript:jpBook($('#13185-SL-CK-1'),'13185','SDAH','DBG','24-10-2015','SL','CK',3,false);");



<没有运气,


没有运气。一个简单的解决方案可能是访问按钮并单击它但我不想这样做




without any luck. A simple solution could be to access the button and click it but i don't want to do that

推荐答案

('#13185-SL-CK-0') ,'13185','SDAH','DBG','24-10-2015','SL','CK',3,false); tabindex = 1 > 立即预订< / a >
('#13185-SL-CK-0'),'13185','SDAH','DBG','24-10-2015','SL','CK',3,false);" tabindex="1">Book Now</a>





在我粘贴href内容时,在我的MozillaBrowser控制台中我得到了预期的结果(JS被执行)。但是在WinForms中。我已经尝试了





In my MozillaBrowser Console when i paste the content of href i get the desired results(the JS is executed).But in WinForms. I have tried

webBrowser1.Navigate("javascript:jpBook(


('#13185-SL-CK-0'), '13185','SDAH','DBG','24-10-2015','SL','CK',3,false););
('#13185-SL-CK-0'),'13185','SDAH','DBG','24-10-2015','SL','CK',3,false);");







webBrowser1.Document.InvokeScript("javascript:jpBook(


( '#13185-SL-CK-1'), '13185', 'SDAH', 'DBG', '24-10-2015', 'SL', 'CK',3,假); );
('#13185-SL-CK-1'),'13185','SDAH','DBG','24-10-2015','SL','CK',3,false);");







没有任何运气。一个简单的解决方案可能是访问按钮并单击它但我不想这样做




without any luck. A simple solution could be to access the button and click it but i don't want to do that


这篇关于在WebBrowser C#中执行JS函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆