python - What is a unique identifier and how to use it to select? -


i use selenium , trying automate task on website , in order select item have use this:

select = driver.find_element_by_*whatever*  

however, whatevers find_element_by_id, name, tag name etc. either unavailable or shared several items. 1 seems unique each item "data-id" number there isn't find_element_by_data_id function far know.

i can unique identifier looks this:

div.item:nth-child(453) 

it seems fit since doesn't change when reload page , unique 1 item.

how can use unique identifier select object? alternatively, suggest way of how select desired item?

here's html pertaining object:

    ... </div> <div data-id="3817366931"      data-slot="secondary"      data-classes="pyro"      data-content="level: 30<br/>"      data-appid="440"      class="item hoverable quality6   app440"      style="opacity:1;background-image:url(https://steamcdn-a.akamaihd.net/apps/440/icons/c_drg_manmelter.b76b87bda3242806c05a6201a4024a560269e805.png);"      data-title="manmelter"      data-defindex="595"> </div> <div data-id="3820690816"      data-slot="primary"      data-classes="pyro"      data-content="level: 10<br/>"      data-appid="440"      class="item hoverable quality6   app440"      style="opacity:1;background-image:url(https://steamcdn-a.akamaihd.net/apps/440/icons/c_drg_phlogistinator.99b83086e28b2f85ed4c925ac5e3c6e123289aec.png);"      data-title="phlogistinator"      data-defindex="594"> </div> <div data-id="3819377317"      data-slot="primary"      data-classes="pyro"      data-content="level: 10<br/>"      data-appid="440"      class="item hoverable quality6   app440"      style="opacity:1;background-image:url(https://steamcdn-a.akamaihd.net/apps/440/icons/c_drg_phlogistinator.99b83086e28b2f85ed4c925ac5e3c6e123289aec.png);"      data-title="phlogistinator"      data-defindex="594"> 

so items in 2 bottom boxes same. 1 @ top different. let's way select item in second box.

i not sure how easy automate scenario based on html structure this. suggest talk devs see if can add kind of ids each parent div otherwise selector brittle. see data-id attribute unique in every case best bet if somehow know ids beforehand. if not have other options css nth-child() function next reliable mechanism. but, in case have know parent. nth-child() explained here

on other hand, if intention find second data-slot can use following xpath:

//div[@data-slot='primary'][2] 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -