-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy path103 HiddenElements.py
64 lines (52 loc) · 2.24 KB
/
103 HiddenElements.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
'''
Created on May 30, 2018
@author: venkateshwara.d
'''
from selenium import webdriver
import time
import os
class HiddenElements():
def testLetsKodeIt(self):
baseUrl = "https://letskodeit.teachable.com/pages/practice"
chrome_driver_path = os.path.abspath('..') + "\\Drivers\\chromedriver.exe"
driver=webdriver.Chrome(chrome_driver_path)
driver.maximize_window()
driver.get(baseUrl)
driver.implicitly_wait(2)
# Find the state of the text box
textBoxElement = driver.find_element_by_id("displayed-text")
textBoxState = textBoxElement.is_displayed() # True if visible, False if hidden
# Exception if not present in the DOM
print("Text is visible? " + str(textBoxState))
time.sleep(2)
# Click the Hide button
driver.find_element_by_id("hide-textbox").click()
# Find the state of the text box
textBoxState = textBoxElement.is_displayed()
print("Text is visible? " + str(textBoxState))
time.sleep(2)
# Added code to scroll up because the element was hiding behind the top navigation menu
# You will learn about scrolling in future lecture
driver.execute_script("window.scrollBy(0, -150);")
# Click the Show button
driver.find_element_by_id("show-textbox").click()
# Find the state of the text box
textBoxState = textBoxElement.is_displayed()
print("Text is visible? " + str(textBoxState))
time.sleep(2)
# Browser Close
driver.quit()
def testExpedia(self):
baseUrl = "http://www.expedia.com"
chrome_driver_path = os.path.abspath('..') + "\\Drivers\\chromedriver.exe"
driver=webdriver.Chrome(chrome_driver_path)
driver.maximize_window()
driver.get(baseUrl)
driver.implicitly_wait(3)
#selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"tab-flight-tab"}
driver.find_element_by_id("tab-flight-tab").click()
drpdwnElement = driver.find_element_by_id("flight-age-select-1")
print("Element visible? " + str(drpdwnElement.is_displayed()))
ff = HiddenElements()
ff.testLetsKodeIt()
ff.testExpedia()