0

enter image description here The issue i have is that the print statement at the end returns NONE . i want to store the values at every 6 spot in each row which is fine and working correctly . BUT the print(self.mystr) at the end doesn't give me a value .

please help/ advise.

i log in to this website and use it . trying to automate a few things.

def click_single_tractor(self): #dynamically clicks tractor
    sleep(2)
    basecss = '#ctl00_ContentPlaceHolder1_PopupControlTractores_TractorGrid_DXMainTable > tbody > tr'
    cssbase = '#ctl00_ContentPlaceHolder1_PopupControlTractores_TractorGrid_DXHeadersRow > td'

    table_rows = self.driver_web_browser.find_elements_by_css_selector(basecss)
    table_data = self.driver_web_browser.find_elements_by_css_selector(cssbase)

    for index, tr in enumerate(table_rows,1):
        iteratingSelObj = self.driver_web_browser.find_elements_by_css_selector("{}:nth-child({})".format( basecss, str(index)))
        print('table row:',int(index))

        for indx, td in enumerate(table_data,1):
            iterate_td = self.driver_web_browser.find_element_by_css_selector("{}:nth-child({})".format( cssbase, str(indx)))
            print('table data:',int(indx))
            if indx == 6:
                #get value of element
                # add to string ? to get value
                

                self.mystr.append(td.get_attribute('text'))


    print(self.mystr)

im displaying the rows and table data on purpose as a self check and it returns the right amount of data
7 rows, 10 table datas per row.

the web table is kind of dynamic because occasionally gets an item added to it which is why im reading the info dynamically that way i dont have to mess with the code if we add an item.

result:

table row: 1

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

table row: 2

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

table row: 3

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

table row: 4

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

table row: 5

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

table row: 6

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

table row: 7

table data: 1 table data: 2 table data: 3 table data: 4 table data: 5 table data: 6 table data: 7 table data: 8 table data: 9 table data: 10

[None, None, None, None, None, None, None]

edward
  • 43
  • 8

1 Answers1

0

text is not an attribute of an Selenium Web Element. We use get_attribute to get attributes of a web element such as its class, id, etc. Basically the stuff you see within the <div id=..., class=.., whatever=... >, the words with the = sign are called properties.

To get the text of a Selenium WebElement simply use td.text, where td is a Selenium Web Element.

A similar question and answer can be found here.

Michael
  • 153
  • 1
  • 6
  • Thanks for the suggestion ! This was what i tried before among a few other things that either didnt run or didnt give me the answer i wanted. this prints out the first row table data only , is it possible this information is protected? – edward Sep 23 '20 at 16:51
  • the first row is not the dynamic info . its just the titles for the table data – edward Sep 23 '20 at 16:54
  • ['Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico'] – edward Sep 23 '20 at 16:55
  • each of those values is the 6th table data info for each row but it should be dynamic – edward Sep 23 '20 at 16:56
  • self.mystr.append(td.text) gives that result – edward Sep 23 '20 at 16:57