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]

2
  • your question is not complete, post also the HTML snippet Commented Sep 21, 2020 at 5:52
  • self.mystr.append(td.text) didnt work for me. is there any other way i can get that value? Commented Sep 23, 2020 at 23:07

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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?
the first row is not the dynamic info . its just the titles for the table data
['Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico', 'Num. Económico']
each of those values is the 6th table data info for each row but it should be dynamic
self.mystr.append(td.text) gives that result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.