How to find child elements in selenium python -


i want find child elements of "row item" , store them in ordered dict form pass excel. html , code given below

<div class = "col-md-5 col-sm-5"     <h3>....</h3>     <div class = "row item">        ::before        <div class = "col-md-6 subtitle"> title</div>        <div class = "col-md-6 ng-binding"> 1233344</div>        ::after      </div>      <div class = "row item">        ::before        <div class = "col-md-6 subtitle"> name</div>        <div class = "col-md-6 ng-binding"> abc</div>        ::after      </div> 

similarly have 23 divs of 'row item' class , want these values in form of ordered dict like

 items_dict = {title:1233344, name:abc} 

my code :

    rowitem in  driver.find_elements_by_xpath('//div[@class="row item"]'):                 titles = rowitem.find_element_by_xpath('.//div[@class="row item"]/div[1]')                 values = rowitem.find_element_by_xpath('//div[@class="row item"]/div[2]')                  title,value in zip(titles,values):                     items_dict[title] = []                     if(title.text , value.text):                         items_dict[title.text].append(value.text) 

try below code removing first loop:

titles = driver.find_element_by_xpath('.//div[@class="row item"]/div[1]') values = driver.find_element_by_xpath('//div[@class="row item"]/div[2]') items_dict={};  title,value in zip(titles,values):        items_dict[title.get_attribute('text')] = value.get_attribute('text') 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -