WebBrowser ID访问 - 不在DocumentText中,而是在页面源中 [英] WebBrowser ID Access - not in DocumentText but in Page Source

查看:363
本文介绍了WebBrowser ID访问 - 不在DocumentText中,而是在页面源中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WebBrowser 对象,用于Web窗体.Net Framework 4.5应用程序的Web自动化目的。在某个网页中,我无法在我的 WebBrowser.DocumentText 中看到ID,即使我可以在打开查看网页源从实际的浏览器。



这是我总是用来获取 HtmlElement 在页面内的代码。 / p>

  var attack = wb.Document.GetElementById(target_attack); 

总结如何检索不在DocumentText内部但在页面源中的ID? / p>

修改:这是页面源数据中的外观。只需按 conrol + f ,然后搜索名为 troop_confirm_go 的I​​D:

 < table align =centerid =contentContainerwidth =100%> 
< tr>
< td>
< table class =content-borderwidth =100%cellspacing =0>
< tr>
< td id =inner-border>
< table class =mainalign =left>
< tr>
< td id =content_value>


< form id =command-data-formaction =/ game.php?village = 39143& amp; screen = place& amp; action = command& amp; h = c86dc3bdmethod =postonsubmit =this.submit.disabled = true;>
< input type =hiddenname =attackvalue =true/>

< h2> Barbarköyühedefindekisaldırıyıonayla< / h2>


< input type =hiddenname =chvalue =b5aa6baff4c83d16a08edb7709204aefd3e85650/>
< input type =hiddenname =xvalue =489/>
< input type =hiddenname =yvalue =690/>
< input type =hiddenname =source_villagevalue =39143>
< input type =hiddenname =action_idvalue =1880595/>

< table class =viswidth =300>
< tr>
< th colspan =2>
Komut
< / th>
< / tr>
< tr>< td> Hedef:< / td>< td>< span class =village_anchordata-player =0data-id =42165> href =/ game.php?village = 39143& amp; screen = info_village& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp = amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp> / tr>
< tr>< td>Süre:< / td>< td> 0:40:15< / td>< / tr>
< tr>
< td>Varış:< / td>
< td id =date_arrival>
< span class =relative_timedata-duration =2415>
bugünsaat 23:46
< / span>
< / td>
< / tr>
< tr>< td>道德:< / td>< td>< b> 100%< / b>< / td>< / tr> < tr>< td colspan =2>< span class =icon header ressourcestitle =Taşımakapasitesi>< / span> 250< / td>< / tr> < / table>< br />

< table class =visid =place_confirm_units>
< tr>
< th class =train-uistyle =display:none>< / th>
< th width =50>< a href =#class =unit_linkdata-unit =spear>< img src =https://dstr.innogamescdn。 com / 8.44.1 / 28599 / graphic / unit / unit_spear.pngtitle =Mızrakçıalt =class =/>< / a>< / th>< th width =50 >< a href =#class =unit_linkdata-unit =sword>< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/ unit_sword.pngtitle =KılıçUstasıalt =class =faded/>< / a>< / th>< th width =50>< a href =# class =unit_linkdata-unit =ax>< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_axe.pngtitle =Baltacıalt =class =faded/>< / a>< / th>< th width =50>< a href =#class =unit_linkdata-unit =spy >< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_spy.pngtitle =Casusalt =class =faded/> < / a>< / th>< th width =50>< a href =#class =unit_linkdata-unit =light>< img src = //dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_light.pngtitle =Hafifatlıalt =class =faded/>< / a>< / th> < th width =50>< a href =#class =unit_linkdata-unit =heavy>< img src =https://dstr.innogamescdn.com/8.44。 1/28599 / graphic / unit / unit_heavy.pngtitle =Ağıratlıalt =class =faded/>< / a>< / th>< th width =50> < a href =#class =unit_linkdata-unit =ram>< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_ram。 pngtitle =Şahmerdanalt =class =faded/>< / a>< / th>< th width =50>< a href =#class = unit_linkdata-unit =catapult>< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_catapult.pngtitle =Mancınıkalt = class =faded/>< / a>< / th>< th width =50>< a href =#class =unit_linkdata-unit =knight> < img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_knight.pngtitle =Şövalyealt =class =faded/>< a>< / th>< th width =50>< a href =#class =unit_linkdata-unit =snob>< img src =https:// dstr .innogamescdn.com / 8.44.1 / 28599 / graphic / unit / unit_snob.pngtitle =Misyoneralt =class =faded/>< / a>< / th&
< / tr>
< tr class =train-uistyle =display:none>
< th>Köybirimleri< / th>
< td class ='unit-item unit-item-spear'> 10< / td>< td class ='unit-item unit-item-sword'> 10< / td> td class ='unit-item unit-item-ax hidden'> 0< / td>< td class ='unit-item unit-item-spy hidden'> 0< / td>< td class =' unit-item unit-item-light hidden'> 0< / td>< td class ='unit-item unit-item-heavy hidden'> 0< / td>< td class ='unit-item unit -item-ram hidden'> 0< / td>< td class ='unit-item unit-item-catapult hidden'> 0< / td>< td class ='unit-item unit-item-knight hidden> 0< / td>< td class ='unit-item unit-item-snob hidden'> 0< / td>
< / tr>
< tr class =units-row>
< th class =train-ui train-namestyle =display:none>< span>Saldırı#1< / span>< / th>
< td class ='unit-item unit-item-spear'> 10< / td>< td class ='unit-item unit-item-sword hidden'> 0< / td> ; td class ='unit-item unit-item-ax hidden'> 0< / td>< td class ='unit-item unit-item-spy hidden'> 0< / td>< td class = 'unit-item unit-item-light hidden'> 0< / td>< td class ='unit-item unit-item-heavy hidden'> 0< / td>< td class = unit-item-item-catapult hidden'> 0< / td>< td class ='unit-item unit-item- knight hidden'> 0< / td>< td class ='unit-item unit-item-snob hidden'> 0< / td>
< / tr>
< tr class =train-ui units-sumstyle =display:none>
< th> Toplam< / th>
< td class ='unit-item unit-item-spear'> 10< / td>< td class ='unit-item unit-item-sword hidden'> 0< / td> ; td class ='unit-item unit-item-ax hidden'> 0< / td>< td class ='unit-item unit-item-spy hidden'> 0< / td>< td class = 'unit-item unit-item-light hidden'> 0< / td>< td class ='unit-item unit-item-heavy hidden'> 0< / td>< td class = unit-item-item-catapult hidden'> 0< / td>< td class ='unit-item unit-item- knight hidden'> 0< / td>< td class ='unit-item unit-item-snob hidden'> 0< / td>
< / tr>
< / table>

< br />

< input type =hiddenname =spearvalue =10/>
< input type =hiddenname =swordvalue =0/>
< input type =hiddenname =axvalue =0/>
< input type =hiddenname =spyvalue =0/>
< input type =hiddenname =lightvalue =0/>
< input type =hiddenname =heavyvalue =0/>
< input type =hiddenname =ramvalue =0/>
< input type =hiddenname =catapultvalue =0/>
< input type =hiddenname =knightvalue =0/>
< input type =hiddenname =snobvalue =0/>

< h3 class =errorid =train_noble_warningstyle =display:none>
Misyonerler koruma olmadangönderilmemeli!
< / h3>

< input id =troop_confirm_gostyle =margin-bottom:5pxclass =troop_confirm_go btn btn-attackname =submittype =submitonload =this.disabled = false; value =Saldırıgönder/>
< a href =#id =troop_confirm_trainclass =btn btn-imgstyle =display:none; line-height:21px>
< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/tiny/snob.pngtitle =alt =class =/> ; Misyonersaldırısıekle
< / a>
< / form>

< script type =text / javascript>
$(document).ready(function(){
$('#troop_confirm_go')。focus();
Place.confirmScreen.init({type:attack units:[spear,sword,ax,spy,light,heavy,ram,catapult,knight,snob],send_units: {spear:10,sword:0,ax:0,spy:0,light:0,heavy:0,ram:0,catapult:0,骑士:0,snob:0},available_units:{spear:10,sword:10,ax:0,spy:0,light:0,heavy :0,ram:0,catapult:0,knight:0,snob:0}});
}
< / script>
< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>
< / td>
< / tr>
< / table>

< p class =server_info>
Sunucu saati:< span id =serverTime> 23:05:56< / span> < span id =serverDate> 08/03/2016< / span>
< span id =dev_consolestyle =display:none>< b> |< / b> < a href =?screen = 74:72:69:62:61:6c:77:61:72:73>开发人员控制台< / a&
< / p>

< / td>
< td class =bg_rightid =SkyScraperAdCell>
< div class =bg_right> < / div>
< div id =SkyScraperAd>
< script type ='text / javascript'><! - //<![CDATA [
var m3_u =(location.protocol =='https:'?'https: //openx.innogames.de/delivery/ajs.php':'http://openx.innogames.de/delivery/ajs.php');
var m3_r = Math.floor(Math.random()* 99999999999);
if(!document.MAX_used)document.MAX_used =',';
document.write(< scr+ipt type ='text / javascript'src ='+ m3_u);
document.write(?zoneid = 1620);
document.write('& amp; cb ='+ m3_r);
if(document.MAX_used!=',')document.write(& amp; exclude =+ document.MAX_used);
document.write(document.charset?'& amp; charset ='+ document.charset:(document.characterSet?'& amp; charset ='+ document.characterSet:''));
document.write(& amp; loc =+ escape(window.location));
if(document.referrer)document.write(& amp; amp; referer =+ escape(document.referrer));
if(document.context)document.write(& context =+ escape(document.context));
if(document.mmm_fo)document.write(& amp; mmm_fo = 1);
document.write('>< \ / scr+ipt>);
//]]> - >< / script>< noscript>< a href ='http://openx.innogames.de/delivery/ck.php?n = a47300e4& amp ; cb = INSERT_RANDOM_NUMBER_HERE'target ='_ blank'>< img src ='http://openx.innogames.de/delivery/avw.php?zoneid = 1620& amp; cb = INSERT_RANDOM_NUMBER_HERE& amp; n = a47300e4' border ='0'alt =''/>< / a>< / noscript>

< / div>
< / td>
< / tr>

< tr>
< td class =bg_leftborder> < / td>
< td>< / td>
< td class =bg_rightborder> < / td>
< / tr>
< tr class =newStyleOnly>
< td class =bg_bottomleft>& nbsp;< / td>
< td class =bg_bottomcenter>& nbsp;< / td>
< td class =bg_bottomright>& nbsp;< / td>
< / tr>
< / table><! - .main_layout - >


< script type =text / javascript>

var _gaq = _gaq || [];
_gaq.push(['_ setAccount','UA-1897727-23']);
_gaq.push(['_ trackPageview']);
_gaq.push(['_ gat._anonymizeIp']);


(function(){
var ga = document.createElement('script'); ga.type ='text / javascript'; ga.async = true;
ga.src =('https:'== document.location.protocol?'https:// ssl':'http:// www')+'.google-analytics.com / ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0])appendChild(ga);
})();

< / script>


< div id =world_selection_clicktrapclass =evt-world-selection-toggle>
< / div>
< div id =world_selection_popup>
< div class =servers-list-top>< / div>
< div id =servers-list-block>

< / div>
< div class =servers-list-bottom>< / div>
< / div>

< div class =chat-open-buffer>< / div>

< div id =bottom>
< div id =chat-shellper>
< / div>

< div id =footer>
< a href =#id =unsupported-browser>
< img src =https://dstr.innogamescdn.com/8.44.1/28599/graphic/error.pngtitle =alt =class =/> Desteklenmeyentarayıcı
< / a>
< div id =linkContainer>
< a href =#class =world_button_active evt-world-selection-toggle> 32。 Dünya< / a>
< a href =http://forum.klanlar.org/index.phpclass =footer-linktarget =_ blank>论坛< / a>
& nbsp; - & nbsp;
< a href =http://help.klanlar.org/wiki/Ana_sayfaclass =footer-linktarget =_ blank>Yardım< / a>
& nbsp; - & nbsp;
< a href =http://blog.klanlar.orgclass =footer-linktarget =_ blank>博客< / a>
& nbsp; - & nbsp;
< a href =/ game.php?village = 39143& amp; screen = settings& amp; mode = ticketclass =footer-linktarget =_ blank> Destek< / a>
& nbsp; - & nbsp;
< a href =/ game.php?village = 39143& amp; screen = settings& amp; mode = ref& amp; source = bottom_menuclass =footer-link> Oyuncu davet et< / a>
& nbsp; - & nbsp;
< a href =/ game.php?village = 39143& amp; screen = memoclass =footer-link>不是defteri< / a>
& nbsp; - & nbsp;
< a href =/ game.php?village = 39143& amp; screen =& amp; action = logout& amp; h = c86dc3bdtarget =_ topclass =footer-link> ;Çıkış< / a>
< / div>
< / div>
< / div>




< script>
$(document).ready(function(){
Timing.init(1457471156.4343);
TribalWars.initTab('1458e0d83d');

$ b b
WorldSwitch.init();
WorldSwitch.worldsURL ='/game.php?village=39143&screen=api&ajax=world_switch&';

HotKeys.init ();

Connection.connect('tr32.klanlar.org',8082,'cec5b6e92cde',true);

UI.Notification.enabled = true;




});

解决方案>

我假设你在某种类型的 wb_DocumentCompleted 事件之后执行你的 wb.Document.GetElementById
不过,你可以在你的html源代码中看到,你正在排队的元素上正在执行javascript,使得它在那段时间很忙,无法访问。



你可能想要尝试的是排队一个元素,它是填充在troop_confirm_go(例如troop_confirm_train)后,一旦这个元素不返回任何东西,你可以尝试并获得你想要的元素再次访问。



编辑:这样的操作应该可以做到:
此函数为具有指定的ID的项目排队键每20毫秒10秒。如果未填充,则取消它。

  public async任务WaitForElementToLoad(String key)
{
element = wb.Document.GetElementById(key);
CancellationToken ct = new CancellationTokenSource(10000).Token;

var doc = wb.Document;
while(true)
{
await Task.Delay(20,ct);

element = wb.Document.GetElementById(key);
if(element!= null)
if(element.InnerHtml!= null)
break;

doc = wb.Document;
}
ct.ThrowIfCancellationRequested();
}

像这样调用它应该可以得到你的troop_confirm_go:

  await WaitForElementToLoad(troop_confirm_train); 
element = wb.Document.GetElementById(troop_confirm_go);

请注意,您调用此函数的函数需要 async


I am using the WebBrowser object, for web automation purposes on a windows form .Net Framework 4.5 application. In a certain page, I am not able to see the id in my WebBrowser.DocumentText even though I can see it when I open View page source from an actual browser.

This is the code that I always use to get the HtmlElement inside a page.

var attack = wb.Document.GetElementById("target_attack");

To sum up how can I retrieve an ID that is not inside DocumentText but inside the page source ?

Edit: This is how it looks like in the Page Source data. Just press conrol + f and search for the id named troop_confirm_go:

<table align="center" id="contentContainer" width="100%">
        <tr>
            <td>
                <table class="content-border" width="100%" cellspacing="0">
                    <tr>
                        <td id="inner-border">
                            <table class="main" align="left">
                                <tr>
                                    <td id="content_value">


                                        <form id="command-data-form" action="/game.php?village=39143&amp;screen=place&amp;action=command&amp;h=c86dc3bd" method="post" onsubmit="this.submit.disabled=true;">
<input type="hidden" name="attack" value="true" />

<h2>Barbar köyü hedefindeki saldırıyı onayla</h2>


<input type="hidden" name="ch" value="b5aa6baff4c83d16a08edb7709204aefd3e85650" />
<input type="hidden" name="x" value="489" />
<input type="hidden" name="y" value="690" />
<input type="hidden" name="source_village" value="39143">
<input type="hidden" name="action_id" value="1880595" />

<table class="vis" width="300">
    <tr>
        <th  colspan="2">
                            Komut
                        </th>
                </tr>
    <tr><td>Hedef:</td><td><span class="village_anchor" data-player="0" data-id="42165"><a href="/game.php?village=39143&amp;screen=info_village&amp;id=42165" >Barbar köyü (489|690) K64</a></span></td></tr>
            <tr><td>Süre:</td><td>0:40:15</td></tr>
    <tr>
        <td>Varış:</td>
        <td id="date_arrival">
            <span class="relative_time" data-duration="2415">
            bugün saat 23:46 
            </span>
                        </td>
    </tr>
    <tr><td>Moral:</td><td><b>100%</b></td></tr>                <tr><td colspan="2"><span class="icon header ressources" title="Taşıma kapasitesi"></span>250</td></tr>    </table><br />

<table class="vis" id="place_confirm_units">
    <tr>
        <th class="train-ui" style="display: none"></th>
        <th width="50"><a href="#" class="unit_link" data-unit="spear"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_spear.png" title="Mızrakçı" alt="" class="" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="sword"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_sword.png" title="Kılıç Ustası" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="axe"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_axe.png" title="Baltacı" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="spy"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_spy.png" title="Casus" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="light"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_light.png" title="Hafif atlı" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="heavy"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_heavy.png" title="Ağır atlı" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="ram"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_ram.png" title="Şahmerdan" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="catapult"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_catapult.png" title="Mancınık" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="knight"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_knight.png" title="Şövalye" alt="" class="faded" /></a></th><th width="50"><a href="#" class="unit_link" data-unit="snob"><img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/unit_snob.png" title="Misyoner" alt="" class="faded" /></a></th>
                </tr>
    <tr class="train-ui" style="display: none">
        <th>Köy birimleri</th>
        <td class='unit-item unit-item-spear '>10</td><td class='unit-item unit-item-sword '>10</td><td class='unit-item unit-item-axe hidden'>0</td><td class='unit-item unit-item-spy hidden'>0</td><td class='unit-item unit-item-light hidden'>0</td><td class='unit-item unit-item-heavy hidden'>0</td><td class='unit-item unit-item-ram hidden'>0</td><td class='unit-item unit-item-catapult hidden'>0</td><td class='unit-item unit-item-knight hidden'>0</td><td class='unit-item unit-item-snob hidden'>0</td>
    </tr>
    <tr class="units-row">
        <th class="train-ui train-name" style="display: none"><span>Saldırı #1</span></th>
        <td class='unit-item unit-item-spear '>10</td><td class='unit-item unit-item-sword hidden'>0</td><td class='unit-item unit-item-axe hidden'>0</td><td class='unit-item unit-item-spy hidden'>0</td><td class='unit-item unit-item-light hidden'>0</td><td class='unit-item unit-item-heavy hidden'>0</td><td class='unit-item unit-item-ram hidden'>0</td><td class='unit-item unit-item-catapult hidden'>0</td><td class='unit-item unit-item-knight hidden'>0</td><td class='unit-item unit-item-snob hidden'>0</td>
                </tr>
    <tr class="train-ui units-sum" style="display: none">
        <th>Toplam</th>
        <td class='unit-item unit-item-spear '>10</td><td class='unit-item unit-item-sword hidden'>0</td><td class='unit-item unit-item-axe hidden'>0</td><td class='unit-item unit-item-spy hidden'>0</td><td class='unit-item unit-item-light hidden'>0</td><td class='unit-item unit-item-heavy hidden'>0</td><td class='unit-item unit-item-ram hidden'>0</td><td class='unit-item unit-item-catapult hidden'>0</td><td class='unit-item unit-item-knight hidden'>0</td><td class='unit-item unit-item-snob hidden'>0</td>
    </tr>
</table>

<br />

    <input type="hidden" name="spear" value="10" />
    <input type="hidden" name="sword" value="0" />
    <input type="hidden" name="axe" value="0" />
    <input type="hidden" name="spy" value="0" />
    <input type="hidden" name="light" value="0" />
    <input type="hidden" name="heavy" value="0" />
    <input type="hidden" name="ram" value="0" />
    <input type="hidden" name="catapult" value="0" />
    <input type="hidden" name="knight" value="0" />
    <input type="hidden" name="snob" value="0" />

<h3 class="error" id="train_noble_warning" style="display: none">
    Misyonerler koruma olmadan gönderilmemeli!
</h3>

<input id="troop_confirm_go" style="margin-bottom: 5px" class="troop_confirm_go btn btn-attack" name="submit" type="submit" onload="this.disabled=false;" value="Saldırı gönder" />
<a href="#" id="troop_confirm_train" class="btn btn-img" style="display: none; line-height: 21px">
    <img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/unit/tiny/snob.png" title="" alt="" class="" /> Misyoner saldırısı ekle
</a>
</form>

 <script type="text/javascript">
 $(document).ready(function() {
    $('#troop_confirm_go').focus();
            Place.confirmScreen.init({"type":"attack","units":["spear","sword","axe","spy","light","heavy","ram","catapult","knight","snob"],"send_units":{"spear":10,"sword":0,"axe":0,"spy":0,"light":0,"heavy":0,"ram":0,"catapult":0,"knight":0,"snob":0},"available_units":{"spear":10,"sword":10,"axe":0,"spy":0,"light":0,"heavy":0,"ram":0,"catapult":0,"knight":0,"snob":0}});
        });
</script>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    <p class="server_info">
        Sunucu saati: <span id="serverTime">23:05:56</span> <span id="serverDate">08/03/2016</span>
        <span id="dev_console" style="display: none"><b>|</b> <a href="?screen=74:72:69:62:61:6c:77:61:72:73">developer console</a></span>
                </p>

</td>
<td class="bg_right" id="SkyScraperAdCell">
    <div class="bg_right"> </div>
                <div id="SkyScraperAd">
            <script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://openx.innogames.de/delivery/ajs.php':'http://openx.innogames.de/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=1620");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://openx.innogames.de/delivery/ck.php?n=a47300e4&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://openx.innogames.de/delivery/avw.php?zoneid=1620&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a47300e4' border='0' alt='' /></a></noscript>

        </div>
        </td>
</tr>

                    <tr>
            <td class="bg_leftborder"> </td>
            <td></td>
            <td class="bg_rightborder"> </td>
        </tr>
        <tr class="newStyleOnly">
            <td class="bg_bottomleft">&nbsp;</td>
            <td class="bg_bottomcenter">&nbsp;</td>
            <td class="bg_bottomright">&nbsp;</td>
        </tr>
                    </table><!-- .main_layout -->


<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1897727-23']);
_gaq.push(['_trackPageview']);
_gaq.push(['_gat._anonymizeIp']);


(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
 (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();

</script>


            <div id="world_selection_clicktrap" class="evt-world-selection-toggle">
    </div>
    <div id="world_selection_popup">
        <div class="servers-list-top"></div>
        <div id="servers-list-block">

        </div>
        <div class="servers-list-bottom"></div>
    </div>

    <div class="chat-open-buffer"></div>

    <div id="bottom">
        <div id="chat-wrapper">
        </div>

        <div id="footer">
            <a href="#" id="unsupported-browser">
                <img src="https://dstr.innogamescdn.com/8.44.1/28599/graphic/error.png" title="" alt="" class="" /> Desteklenmeyen tarayıcı
            </a>
            <div id="linkContainer">
                                    <a href="#" class="world_button_active evt-world-selection-toggle">32. Dünya</a>
                                    <a href="http://forum.klanlar.org/index.php" class="footer-link" target="_blank">Forum</a>
                &nbsp;-&nbsp;
                <a href="http://help.klanlar.org/wiki/Ana_sayfa" class="footer-link" target="_blank">Yardım</a>
                                        &nbsp;-&nbsp;
                    <a href="http://blog.klanlar.org" class="footer-link" target="_blank">Blog</a>
                                                        &nbsp;-&nbsp;
                <a href="/game.php?village=39143&amp;screen=settings&amp;mode=ticket" class="footer-link" target="_blank">Destek</a>
                                                            &nbsp;-&nbsp;
                    <a href="/game.php?village=39143&amp;screen=settings&amp;mode=ref&amp;source=bottom_menu" class="footer-link">Oyuncu davet et</a>
                                                        &nbsp;-&nbsp;
                <a href="/game.php?village=39143&amp;screen=memo" class="footer-link">Not defteri</a>
                                                                            &nbsp;-&nbsp;
                <a href="/game.php?village=39143&amp;screen=&amp;action=logout&amp;h=c86dc3bd" target="_top" class="footer-link">Çıkış</a>
                                </div>
        </div>
    </div>




<script>
$(document).ready(function() {
    Timing.init(1457471156.4343);
    TribalWars.initTab('1458e0d83d');



        WorldSwitch.init();
    WorldSwitch.worldsURL = '/game.php?village=39143&screen=api&ajax=world_switch&';

        HotKeys.init();

        Connection.connect('tr32.klanlar.org', 8082, 'cec5b6e92cde', true);

        UI.Notification.enabled = true;




    });

解决方案

I am assuming you execute your wb.Document.GetElementById after some kind of wb_DocumentCompleted event. However, as you can see in your html source, there is javascript being executed on the element you are queuing for, making it busy and inaccessible by that time.

What you might want to try is queuing for an element, which is populated after "troop_confirm_go" (e.g. "troop_confirm_train") and as soon as this element does not return nothing, you can try and get the element you're trying to access again.

EDIT: Something like this should do the trick: This function queues for the item with the id specified in key every 20 ms for 10 seconds. If it is not populated it is cancelled.

public async Task WaitForElementToLoad(String key)
    {
        element = wb.Document.GetElementById(key);
        CancellationToken ct = new CancellationTokenSource(10000).Token;

        var doc = wb.Document;
        while (true)
        {
            await Task.Delay(20, ct);

            element = wb.Document.GetElementById(key);
            if (element != null)
                if (element.InnerHtml != null)
                    break;

            doc = wb.Document;
        }
        ct.ThrowIfCancellationRequested();
    }

Calling it like this should get you your troop_confirm_go:

await WaitForElementToLoad("troop_confirm_train");
element = wb.Document.GetElementById("troop_confirm_go");

Note that the function you call this from needs to be async too.

这篇关于WebBrowser ID访问 - 不在DocumentText中,而是在页面源中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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