1

I am trying to use selenium to grab text data from a page.

Printing the html attributes:

element = driver.find_element_by_id("divresults")

Results:

print(element.get_attribute('innerHTML'))

<div id="divDesktopResults"> </div>

Results:

print(element.get_attribute('outerHTML'))

<div id="divresults" data-bind="html:resultsContent"><div id="divDesktopResults"> </div></div>

Tried grabbing this element

Results:

driver.find_element_by_css_selector("span[class='glyphicon glyphicon-tasks']")


Message: no such element: Unable to locate element: {"method":"css selector","selector":"span[class='glyphicon glyphicon-tasks']"}

This is the code when copied from the Browser. There is much more below 'divresults' that did not show up in the innerhtml printout

<div id="divresults" data-bind="html:resultsContent">
    <div> 
        <div class="row" style="font-size:8pt;"> 
            <a data-toggle="tooltip" style="text-decoration:underline" href="#pdfviewer?ID=D218101736">  
                <strong>D218101736 </strong>  
                <span class="glyphicon glyphicon-new-window"></span> 
            </a> 
        <div class="btn-group" style="font-size:8pt;margin-left:10px;" id="btnD218101736">   
            <span style="display:none;font-size:8pt;" id="lblD218101736"> Added To Cart</span> 
            <button type="button" style="font-size:8pt;" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> Add To Cart 
                <span class="caret"></span> 
            </button> 
                <ul class="dropdown-menu" role="menu"> 
                    <li> <a href="#" onclick="addToCart('D218101736', event)"><strong>Regular ($7.00)</strong></a> </li> 
                    <li> <a href="#" onclick="addToCartCertified('D218101736', event)"><strong>Certified ($12.00)</strong></a> </li> 
                </ul> 
        </div>  
    </div> <br> 

    <ul class="nav nav-tabs compact"> 
        <li class="active"> 
            <a data-toggle="tab" href="#D218101736_Doc"> 
                <span class="glyphicon glyphicon-file"></span>  
                <span>Doc Info</span> 
            </a> 
        </li> 
        <li class="hidden-xs"> 
            <a data-toggle="tab" href="#D218101736_Thumbnail"> 
                <span class="glyphicon glyphicon-th-large"></span>  
                <span>Thumbnail</span>
            </a> 
        </li> 
       ....

How to I get data beneath divresults in the instance?

user9794893
  • 133
  • 3
  • 11

1 Answers1

0

My guess is that it's one of two things:

  1. There is more than one element that matches that locator. To investigate this, try using $$("#divresults") in the dev console and make sure that it returns 1. If it returns more than one, run $$("#divresults")[0] and make sure the element returned is the one you want. If it is, go on to step 2. If it isn't, you will need to find a locator that is more specific. If you want our help, you will need to provide a link to the page or more of the surrounding HTML to the desired element.
  2. You need to add a wait so that the contents of the element can finish loading. You could wait for a locator like #divresults strong or any number of locators to find some of the elements that were missing. You would wait for them to be visible (or at least present). See the docs for more info and options.
JeffC
  • 22,180
  • 5
  • 32
  • 55