I am developing a web bot using WinForms WebBrowser control. Everything is working fine except for the second click()
call in following code:
function SaveRecordClick() {
try {
var menuButton = $('#s_at_m_4');
menuButton.click(); //<-- This is working
var x = $('#s_at_m_4-menu li')[5];
var saveLink = $(x).find('a')[0];
if (saveLink != null){
saveLink.click(); //<-- This is not working
return "1";
}
}
catch (err) {
alert(err.message);
}
return "0";
}
saveLink
is not null. I know this because I placed an alert()
call inside the condition.
Updated code with suggested solutions
function SaveRecordClick() {
try {
var menuButton = $('#s_at_m_4');
menuButton.click();
var x = $('#s_at_m_4-menu li').eq(5);
var saveLink = x.find('a').eq(0);
if (saveLink != null) {
alert(saveLink.html());
saveLink.click();
return "1";
}
}
catch (err) {
alert(err.message);
}
return "0";
}
But still the same problem. 'alert()' is working fine but html()
is showing inner text instead of HTML of the anchor.
HTML Code
<li data-caption="Save Record [Ctrl+S]" class="sbui-appletmenu-item ui-menu-item" role="presentation">
<a href="javascript:void(0)" aria-disabled="false" class="ui-corner-all" id="ui-id-254" tabindex="-1" role="menuitem">Save Record [Ctrl+S]</a>
</li>
ID
of the anchor tag is dynamically generated.
Also, click()
is triggering when the same code is executed from Google Chrome Console. So, could it be the issue with the WebBrowser control?
Update
I think guys its a problem with the webrowser control that inherits Internet Explorer. So now I am shifting to another browser control and testing the code on it. Will let you know if it works there.