1
1
using HtmlAgilityPack ;
2
2
using OpenQA . Selenium ;
3
+ using OpenQA . Selenium . Support . UI ;
3
4
using System ;
4
5
using System . Linq ;
5
6
using System . Threading . Tasks ;
@@ -299,36 +300,38 @@ public static async Task<bool> ToHero(Account acc, HeroTab tab)
299
300
return false ;
300
301
}
301
302
elements [ 0 ] . Click ( ) ;
302
- {
303
- var result = await DriverHelper . WaitPageChange ( acc , "/hero/inventory" ) ;
304
303
305
- if ( ! result )
306
- {
307
- acc . Logger . Warning ( $ "Click Hero avatar failed") ;
308
- return false ;
309
- }
310
- }
304
+ var wait = new WebDriverWait ( acc . Wb . Driver , TimeSpan . FromMinutes ( 1 ) ) ;
305
+ wait . Until ( driver =>
306
+ {
307
+ acc . Wb . UpdateHtml ( ) ;
308
+ var heroDiv = acc . Wb . Html . GetElementbyId ( "heroV2" ) ;
309
+ if ( heroDiv == null ) return false ;
310
+ var aNode = heroDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == 1 ) ;
311
+ if ( aNode == null ) return false ;
312
+ return aNode . HasClass ( "active" ) ;
313
+ } ) ;
311
314
312
315
if ( tab == HeroTab . Inventory ) return true ;
313
316
314
317
var navigatorDiv = acc . Wb . Html . GetElementbyId ( "heroV2" ) ;
315
- var index = tab == HeroTab . Attributes ? 2 : 3 ;
316
- var tabNode = navigatorDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == index ) ;
318
+ var tabNode = navigatorDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == ( int ) tab ) ;
317
319
if ( tabNode == null ) return false ;
318
320
var tabElements = acc . Wb . Driver . FindElements ( By . XPath ( tabNode . XPath ) ) ;
319
321
if ( tabElements . Count == 0 ) return false ;
320
322
tabElements [ 0 ] . Click ( ) ;
321
- {
322
- await Task . Delay ( 800 ) ;
323
- var result = await DriverHelper . WaitPageLoaded ( acc ) ;
324
323
325
- if ( ! result )
326
- {
327
- acc . Logger . Warning ( $ "Click Change tab failed") ;
328
- return false ;
329
- }
330
- }
331
- return true ;
324
+ wait . Until ( driver =>
325
+ {
326
+ acc . Wb . UpdateHtml ( ) ;
327
+ var heroDiv = acc . Wb . Html . GetElementbyId ( "heroV2" ) ;
328
+ if ( heroDiv == null ) return false ;
329
+ var aNode = heroDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == ( int ) tab ) ;
330
+ if ( aNode == null ) return false ;
331
+ return aNode . HasClass ( "active" ) ;
332
+ } ) ;
333
+
334
+ return await DriverHelper . WaitPageLoaded ( acc ) ;
332
335
}
333
336
334
337
public static async Task < bool > ToAdventure ( Account acc )
@@ -346,16 +349,21 @@ public static async Task<bool> ToAdventure(Account acc)
346
349
return false ;
347
350
}
348
351
elements [ 0 ] . Click ( ) ;
349
- {
350
- var result = await DriverHelper . WaitPageLoaded ( acc ) ;
351
- acc . Logger . Warning ( $ "Click Adventures button failed") ;
352
352
353
- if ( ! result ) return false ;
354
- }
355
- return true ;
353
+ var wait = new WebDriverWait ( acc . Wb . Driver , TimeSpan . FromMinutes ( 1 ) ) ;
354
+ wait . Until ( driver =>
355
+ {
356
+ acc . Wb . UpdateHtml ( ) ;
357
+ var adventureDiv = acc . Wb . Html . GetElementbyId ( "heroAdventure" ) ;
358
+ if ( adventureDiv == null ) return false ;
359
+ var heroState = adventureDiv . Descendants ( "div" ) . FirstOrDefault ( x => x . HasClass ( "heroState" ) ) ;
360
+ if ( heroState == null ) return false ;
361
+ return driver . FindElements ( By . XPath ( heroState . XPath ) ) . Count > 0 ;
362
+ } ) ;
363
+ return await DriverHelper . WaitPageLoaded ( acc ) ;
356
364
}
357
365
358
- public static async Task < bool > ToAuction ( Account acc )
366
+ public static async Task < bool > ToAuction ( Account acc , AuctionTab tab )
359
367
{
360
368
var node = acc . Wb . Html . DocumentNode . Descendants ( ) . FirstOrDefault ( x => x . HasClass ( "auction" ) ) ;
361
369
if ( node == null )
@@ -370,13 +378,38 @@ public static async Task<bool> ToAuction(Account acc)
370
378
return false ;
371
379
}
372
380
elements [ 0 ] . Click ( ) ;
381
+
382
+ var wait = new WebDriverWait ( acc . Wb . Driver , TimeSpan . FromMinutes ( 1 ) ) ;
383
+ wait . Until ( driver =>
373
384
{
374
- var result = await DriverHelper . WaitPageLoaded ( acc ) ;
375
- acc . Logger . Warning ( $ "Click Auction button failed") ;
385
+ acc . Wb . UpdateHtml ( ) ;
386
+ var auctionDiv = acc . Wb . Html . GetElementbyId ( "heroAuction" ) ;
387
+ if ( auctionDiv == null ) return false ;
388
+ var aNode = auctionDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == 1 ) ;
389
+ if ( aNode == null ) return false ;
390
+ return aNode . HasClass ( "active" ) ;
391
+ } ) ;
392
+
393
+ if ( tab == AuctionTab . Buy ) return true ;
394
+
395
+ var navigatorDiv = acc . Wb . Html . GetElementbyId ( "heroAuction" ) ;
396
+ var tabNode = navigatorDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == ( int ) tab ) ;
397
+ if ( tabNode == null ) return false ;
398
+ var tabElements = acc . Wb . Driver . FindElements ( By . XPath ( tabNode . XPath ) ) ;
399
+ if ( tabElements . Count == 0 ) return false ;
400
+ tabElements [ 0 ] . Click ( ) ;
376
401
377
- if ( ! result ) return false ;
378
- }
379
- return true ;
402
+ wait . Until ( driver =>
403
+ {
404
+ acc . Wb . UpdateHtml ( ) ;
405
+ var auctionDiv = acc . Wb . Html . GetElementbyId ( "heroAuction" ) ;
406
+ if ( auctionDiv == null ) return false ;
407
+ var aNode = auctionDiv . Descendants ( "a" ) . FirstOrDefault ( x => x . GetAttributeValue ( "data-tab" , 0 ) == ( int ) tab ) ;
408
+ if ( aNode == null ) return false ;
409
+ return aNode . HasClass ( "active" ) ;
410
+ } ) ;
411
+
412
+ return await DriverHelper . WaitPageLoaded ( acc ) ;
380
413
}
381
414
382
415
public static async Task < bool > ToOverview ( Account acc , OverviewTab tab , TroopOverview subTab = TroopOverview . OwnTroops )
@@ -473,11 +506,19 @@ public enum TreasuryTab
473
506
474
507
public enum HeroTab
475
508
{
476
- Inventory = 0 ,
509
+ Inventory = 1 ,
477
510
Attributes ,
478
511
Appearance ,
479
512
}
480
513
514
+ public enum AuctionTab
515
+ {
516
+ Buy = 1 ,
517
+ Sell ,
518
+ Bids ,
519
+ Silver ,
520
+ }
521
+
481
522
public enum OverviewTab
482
523
{
483
524
Overview = 0 ,
0 commit comments