1

Here is the code....

from selenium import webdriver

url = 'https://infobypokharelk.blogspot.com/'
driver = webdriver.Firefox()
driver.get(url)

row_count = len(driver.find_elements_by_xpath("//*[@id='post-body-6767393087210111064']/div[1]/table/tbody/tr"))
col_count = len(driver.find_elements_by_xpath("//*[@id='post-body-6767393087210111064']/div[1]/table/tbody/tr[1]/td"))

print("Number if Rows:",row_count)
print("Number of Columns",col_count)

first_part = "//*[@id='post-body-6767393087210111064']/div[1]/table/tbody/tr["
secound_part = "]/td["
third_part = "]"

for n in range(1,row_count+1):
    for m in range(1,col_count+1):
        final_path = first_part + str(n) + secound_part + str(m) + third_part
        table_data = driver.find_elements_by_xpath(final_path).text
        print(table_data,end = " ")
    print()

And the output is..

 File "tut_td.py", line 15, in <module>
    table_data = driver.find_elements_by_xpath(final_path).text
 AttributeError: 'list' object has no attribute 'text'

1 Answer 1

5

find_elements_by_xpath returns a list of elements not just one, so you need iterate over them with a loop or just grab the first one if you believe it to be the only one:

table_data = driver.find_elements_by_xpath(final_path)[0].text
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.