2-10 Enter the registered user name and get user information .py

webdriver the Selenium Import from 
Import Time
# import expected_conditions expected package to determine whether the correct title:
from selenium.webdriver.support Import expected_conditions AS EC
# import WebDriverWait
from selenium.webdriver.support.wait Import WebDriverWait
# imported by:
from selenium.webdriver.common. by Import by
Driver = webdriver.Chrome ()
driver.maximize_window ()
driver.get ( "http://www.5itest.cn/register")
# representatives EC.title_is #title_is current title and the title is the same as expected
the time.sleep (5)
Print (EC.title_contains ( "Register")) #title_contains behalf as long as it contains
# = driver.find_element_by_class_name element ( "Controls")
# get By positioning element:
Locator = (By.CLASS_NAME , "controls")
#Visibility_of_element_located use visibility / visibility:
EC.visibility_of_element_located # (Element)
# use until WebDriverWait find parent element:
WebDriverWait (Driver, 1) .until (EC.visibility_of_element_located (Locator))
# get the e-mail address:
email_element = driver.find_element_by_id ( "register_email")
# text attribute information taken:
Print (email_element.get_attribute ( "placeholder"))
# input information:
email_element.send_keys ( "[email protected]")
# get the value:
Print (email_element.get_attribute ( "value"))
# Close driver can effectively avoid the computer and browser Caton:
driver.close ()
existing position #presence_of_element_located elements:
EC.presence_of_element_located ()
# use id to locate e-mail address:
. # driver.find_element_by_id ( "register_email") send_keys ( "1320685524 @ qq.com ")
# Class using targeting username, find_elements_by_class_name returns a list, the list can len, define the parent class, then the subclass definitions:
# = user_name_element_node driver.find_elements_by_class_name ( "Controls") [. 1]
# = user_element user_name_element_node.find_element_by_class_name ( " Control-form ")
# user_element.send_keys (" dsads ")
# name anchor password using:
# driver.find_element_by_name (" password 990496256dd ")") send_keys (. "
# xpath positioning using codes:
# driver.find_element_by_xpath ( '/ /*[@id="captcha_code"]').send_keys("111111 ")

Guess you like

Origin www.cnblogs.com/zhang-da/p/12129045.html