1

<li id="button1" class="on">
   <div class="supply1">
      <div class="buildingimg">
         <a class="fastBuild tooltip js_hideTipOnMobile" title="Metallmine auf Stufe 4 ausbauen" href="javascript:void(0);" onclick="sendBuildRequest('https://s159-de.ogame.gameforge.com/game/index.php?page=resources&amp;modus=1&amp;type=1&amp;menge=1&amp;token=0c86d8a8bf9a5c559538b0e13cb462b4', null, 1);">
         <img src="https://gf2.geo.gfsrv.net/cdndf/3e567d6f16d040326c7a0ea29a4f41.gif" width="22" height="14">
         </a>
         <a class="detail_button tooltip js_hideTipOnMobile slideIn" title="" ref="1" id="details" href="javascript:void(0);">
         <span class="ecke">
         <span class="level">
         <span class="textlabel">
         **Metallmine** 
         </span>
         **3**                            </span>
         </span>
         </a>
      </div>
   </div>
</li>
<li id="button2" class="on">
   <div class="supply2">
      <div class="buildingimg">
         <a class="fastBuild tooltip js_hideTipOnMobile" title="" href="javascript:void(0);" onclick="sendBuildRequest('https://s159-de.ogame.gameforge.com/game/index.php?page=resources&amp;modus=1&amp;type=2&amp;menge=1&amp;token=0c86d8a8bf9a5c559538b0e13cb462b4', null, 1);">
         <img src="https://gf2.geo.gfsrv.net/cdndf/3e567d6f16d040326c7a0ea29a4f41.gif" width="22" height="14">
         </a>
         <a class="detail_button tooltip js_hideTipOnMobile slideIn" title="" ref="2" id="details" href="javascript:void(0);">
         <span class="ecke">
         <span class="level">
         <span class="textlabel">
         **Kristallmine** 
         </span>
         **1**                            </span>
         </span>
         </a>
      </div>
   </div>
</li>

Dear Community, So I want to create a bot for a browser game (just for learning purposes of course). In the game you can build and level up metal and crystall mines to get more resources. To have the best resource proportions it is best to have a metal mine which is always 2 levels higher, than your crystal mine. Writing the code to compare the levels is no problem, but I'm having problems accessing the actual values of the "level" of the mine since there is no unique attribute to them. Above in the code you can see the "Metallmine" and "Kristallmine" and the corresponding levels. I would like to write a code similar to:

if LevelOfKristallmine - LevelOfMetallmine <-2 driver.find_element_by_whatever('upgradebutton').click()

how can I get the values of LevelOfKristallmine and LevelOfMetallmine?

Thanks alot for your answers!

alfonso
  • 884
  • 17
  • 31
Leo blubla
  • 33
  • 7

1 Answers1

0

You are trying to use the ID, I assume as the values? Instead copy and paste the XPath, using something like:

 driver.find_element_by_xpath('*//*[@id="example-xpath"]/div/nav/ol*').click()

To copy Xpath, f12, find the element to click, right click, copy > Xpath. Then paste in the parentheses. Follow this other link and you should figure it out mate.

Hasta Tamang
  • 2,205
  • 1
  • 18
  • 17
  • Cool man, thanks alot. driver.find_element_by_xpath("//*[@ref='1']/span/span").text worked! I could not just copy the Xpath, because it copied two time the same Xpath for the level of the crystalmine and the metalmine. – Leo blubla Feb 25 '19 at 21:29
  • You can use a browser extension that can find the xpath for all similar elements or for single elements. One I like to use is called SelectorGadget. https://selectorgadget.com/ – alfonso Feb 25 '19 at 22:10