I'm trying to retrieve data from the dynamic web table in selenium python but errors in a console as ERROR as "
values = self.driver.find_element_by_xpath(".//*[@id='table01']/tbody/tr["+row+"]/td["+col+"]").text
TypeError: must be str, not int
FAILED (errors=1)
class DynamicWebTable1(unittest.TestCase):
@classmethod
def setUpClass(cls):
chrome_driver_path = os.path.abspath('..') + "\\Drivers\\chromedriver.exe"
cls.driver=webdriver.Chrome(chrome_driver_path)
cls.driver.implicitly_wait(30)
cls.driver.maximize_window()
# navigate to the application home page
cls.driver.get("http://qavalidation.com/demo/")
def test_get_table_data(self):
time.sleep(10)
columns = len(self.driver.find_elements_by_xpath(".//*[@id='table01']/tbody/tr[1]/td"))
rows = len(self.driver.find_elements_by_xpath(".//*[@id='table01']/tbody/tr"))
print("rows - ",rows) # rows - 3
print("columns - ",columns) #columns - 4
for row in range(rows):
for col in range(columns):
values = self.driver.find_element_by_xpath(".//*[@id='table01']/tbody/tr["+row+"]/td["+col+"]").text
print(" Dynamic web table index {row} ,{col} value is {values} ".format(row, col, values))
@classmethod
def tearDownClass(cls):
# close the browser window
cls.driver.quit()
Github sample code https://github.com/venkywarriors619/selenium_with_python/blob/master/Python_basics/SeleniumWebDriver_Advanced/DynamicWebTable1.py
dynamic we table from http://qavalidation.com/demo/
values = self.driver.find_element_by_xpath(".//*[@id='table01']/tbody/tr[%s]/td[%s]" % (row, col)).text