-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter9.py
51 lines (42 loc) · 1.55 KB
/
chapter9.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
"""
Created by 2020/12/01
QQ: 2574674466
微信公众号:TimTest
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
with webdriver.Firefox() as driver:
driver.get("http://www.myweb.com:8000/admin/login/?next=/admin/")
"""
driver.find_element(By.NAME,"username").send_keys("jack")
#find elements
elements = driver.find_elements(By.TAG_NAME,"li")
print(type(elements))
for e in elements:
print(e)
#find element from element
p_element = driver.find_element(By.CSS_SELECTOR,"li.full:nth-child(1)")
p_element.find_element(By.NAME,"username").send_keys("tom")
time.sleep(3)
#find elements from element
p_element2 = driver.find_element(By.CSS_SELECTOR,".fields")
c_elements = p_element2.find_elements(By.TAG_NAME,"li")
print(type(c_elements))
for e in c_elements:
print(e)
"""
driver.find_element(By.NAME,"username").send_keys("jack")
attr1 = driver.switch_to.active_element.get_attribute("placeholder")
print(attr1)
#6. is element enabled.
value = driver.find_element(By.NAME, "username").is_enabled()
print(value)
tag_name = driver.find_element(By.NAME, "username").tag_name
print("tag_name " + tag_name)
rect = driver.find_element(By.NAME, "username").rect
print(rect)
col = driver.find_element(By.NAME, "username").value_of_css_property('color')
print("color is:" + col)
text = driver.find_element(By.CSS_SELECTOR,".content-wrapper > form:nth-child(1) > h1:nth-child(3)").text
print("text is: " + text)