-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss_vs_xpath.py
82 lines (41 loc) · 1.99 KB
/
css_vs_xpath.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from argparse import Action
from ctypes import alignment
import imp
from lib2to3.pgen2 import driver
from threading import Thread
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import TimeoutException
import selenium.common.exceptions
import sys
from time import sleep
from time import perf_counter
from driver import setup_driver
from gecko_driver import firefox_setup_driver
from random import randint
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
if __name__ == "__main__":
chrome_webdriver = setup_driver()
ui_action = ActionChains(chrome_webdriver)
chrome_webdriver.get("https://amazon.in")
sleep(5)
start_xpath = perf_counter()
element2 = chrome_webdriver.find_element(By.XPATH, "//div[@class='nav-fill']/div/input[@id = 'twotabsearchtextbox']")
end_xpath = perf_counter()
sleep(5)
start_time_css = perf_counter()
element = chrome_webdriver.find_element(By.ID, "twotabsearchtextbox")
end_time_css = perf_counter()
sleep(5)
# selenium is not a good tool to measure the time taken to measure how long it takes to find element
# Xpath would take longer time to find elements because it would take it lot of time to scan dom from start to finish
# traversals can be from parent to child and vice versa
# other selectors would use lesser time since we directly specify what elements we want to find and it can be directly fetched
#easily and there are no traversals
print("{0} seconds css vs {1} XPATH seconds ".format((end_time_css - start_time_css),(end_xpath - start_xpath)))