-
Notifications
You must be signed in to change notification settings - Fork 0
/
13-tables.py
29 lines (22 loc) · 1001 Bytes
/
13-tables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
# Chrome driver
driver = webdriver.Chrome(executable_path=r"C:\Users\Majestic\Documents\QA\drivers\chromedriver.exe")
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("https://the-internet.herokuapp.com/tables")
# Count total rows (using xpath)
tableRows = len(driver.find_elements(By.XPATH,"/html/body/div[2]/div/div/table[1]/tbody/tr"))
print('Number of rows:', tableRows)
# Count total columns (using xpath)
tableColumns = len(driver.find_elements(By.XPATH,"/html/body/div[2]/div/div/table[1]/thead/tr/th"))
print('Number of columns:', tableColumns)
# Read tables
for r in range(tableRows+1):
for c in range(tableColumns+1):
value = driver.find_element_by_xpath("/html/body/div[2]/div/div/table[1]/tbody/tr["+str(r)+"]/td["+str(c)+"]")
print(value.text)
driver.quit()
# For some reaseon the above exercice doesn't work...