Trouble finding element in Selenium with Python -


i have been trying collect list of live channels/viewers on youtube gaming. using selenium python force website scroll down page loads more 11 channels. reference, this webpage working on.

i have found location of data want, struggling getting selenium go there. part having trouble looks this:

<div class="style-scope ytg-gaming-video-renderer" id="video-metadata"><span class="title ellipsis-2 style-scope ytg-gaming-video-renderer"><ytg-nav-endpoint class="style-scope ytg-gaming-video-renderer x-scope ytg-nav-endpoint-2"><a href="/watch?v=ffksd1hhrda" tabindex="0" class="style-scope ytg-nav-endpoint" target="_blank">               live met bo3             </a></ytg-nav-endpoint></span>     <div class="channel-info small layout horizontal center style-scope ytg-gaming-video-renderer">         <ytg-owner-badges class="style-scope ytg-gaming-video-renderer x-scope ytg-owner-badges-0">             <template class="style-scope ytg-owner-badges" is="dom-repeat"></template>         </ytg-owner-badges>         <ytg-formatted-string class="style-scope ytg-gaming-video-renderer">             <ytg-nav-endpoint class="style-scope ytg-formatted-string x-scope ytg-nav-endpoint-2"><a href="/channel/ucd8q9v5wgo8o0xgfuqsrrdq" tabindex="0" class="style-scope ytg-nav-endpoint" target="_blank">rico eeman</a>             </ytg-nav-endpoint>         </ytg-formatted-string>     </div><span class="ellipsis-1 small style-scope ytg-gaming-video-renderer" id="video-viewership-info" hidden=""></span>     <div id="metadata-badges" class="small style-scope ytg-gaming-video-renderer">         <ytg-live-badge-renderer class="style-scope ytg-gaming-video-renderer x-scope ytg-live-badge-renderer-1">             <template class="style-scope ytg-live-badge-renderer" is="dom-if"></template>              <span aria-label="" class="text layout horizontal center style-scope ytg-live-badge-renderer">4 watching</span>             <template class="style-scope ytg-live-badge-renderer" is="dom-if"></template>         </ytg-live-badge-renderer>     </div> </div> 

currently, trying:

#this part works fine. can use unique id meta_data = driver.find_element_by_id('video-metadata')  #this part fine. once again, has id. viewers = meta_data.find_element_by_id('metadata-badges') print(viewers.text) 

however, have been having trouble getting channel name (in example 'rico eeman', , under first nested div tag). because compound class name, cannot find element class name, , trying following xpaths doesnt work:

name = meta_data.find_element_by_xpath('/div[@class="channel-info small layout horizontal center style-scope ytg-gaming-video-renderer"]/ytg-formatted-string'  name = meta_data.find_element_by_xpath('/div[1]) 

they both raise element not found error. not sure here. have working solution?


the name id not in <ytg-formatted-string> tag, in 1 of descendants. try

meta_data.find_element_by_css_selector('.style-scope.ytg-formatted-string.x-scope.ytg-nav-endpoint-2 > a') 

or xpath

meta_data.find_element_by_xpath('//ytg-nav-endpoint[@class="style-scope ytg-formatted-string x-scope ytg-nav-endpoint-2"]/a') 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -