开发者

How to get the HTML element in an new windows triggered by javascript?

开发者 https://www.devze.com 2023-02-17 19:56 出处:网络
i\'m using WebBrowser control in Windows Forms App to automate a website and do some actions, so i need to know the HTML elements in the website(for example, textbox id, button id).

i'm using WebBrowser control in Windows Forms App to automate a website and do some actions, so i need to know the HTML elements in the website(for example, textbox id, button id).

Everything is running smooth until i meet one situation. There are a html link element which point back to itself (eg: "http://www.aaa.com") but trigger a new windows with different url (eg: "http://www.bbb.com"). Below is the html link element :

< a href="#" class="toolbar" id="Export_Link" onclick="showExportWindow();" title="Export me">Exports &amp; Reports< /a>

It 开发者_StackOverflow社区showed up a new window with different url and therefore, the WebBrowser control unable to get the HTML element in the new window because it trace back the html element in the old window ("http://www.aaa.com#") and not the new window ("http://www.bbb.com")

Please help me! I'm stucking here for 1 weeks already! Anyone know how to solve this problem?


I'm not sure if i understand your problem correctly, but it seems that you are struggling with the "#" link. It's a common practice to link to the external page, even if you want to use javascript to open this page. This provides a good fallback for browsers with disabled javascript support.

<a href="otherpage.html" onclick="window.open('otherpage.html','external'); return false;">Other</a>

Pay regard to the return false; at the end of the javascript, it's necessary to tell the browser that the "normal" page link shouldn't be followed when the javascript runs.

0

精彩评论

暂无评论...
验证码 换一张
取 消