-
Notifications
You must be signed in to change notification settings - Fork 0
/
Handling_WebTable.py
46 lines (37 loc) · 1.46 KB
/
Handling_WebTable.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import time
from selenium import webdriver
from selenium.common import NoSuchElementException
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=options, service=ChromeService(ChromeDriverManager().install()))
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("https://www.way2automation.com/angularjs-protractor/webtables/")
#-------------First Method-------------------------
row_count = driver.find_elements(By.XPATH,'//tbody/tr')
total_rows =len(row_count)
#
column_count = driver.find_elements(By.XPATH,'//tbody/tr[1]/td')
total_colums =len(column_count)
#
#
# for i in row_count:
# print("Row : "+i.text)
#
#-------------Second Method-------------------------
start_path ="//tbody/tr["
mid_path ="]/td["
end_path ="]"
for row in range(1,total_rows+1):
for col in range(1,total_colums+1):
final_path = start_path+str(row)+mid_path+str(col)+end_path
print(driver.find_element(By.XPATH,final_path).text,end=" ")
print()