标签:des style http color strong os
以下方法都可以用来定位某个对象,优先选择id,name.
login_form = driver.find_element_by_id(‘loginForm‘)
username = driver.find_element_by_name(‘username‘)
password = driver.find_element_by_name(‘password‘)
login_form = driver.find_element_by_xpath("/html/body/form[1]")
相对路径元素位置
login_form = driver.find_element_by_xpath("//form[1]")
相对路径元素属性
login_form = driver.find_element_by_xpath("//form[@id=‘loginForm‘]")
相对路径子元素的name属性
username = driver.find_element_by_xpath("//form[input/@name=‘username‘]")
相对路径id熟悉后index
username = driver.find_element_by_xpath("//form[@id=‘loginForm‘]/input[1]")
相对路径name属性
username = driver.find_element_by_xpath("//input[@name=‘username‘]")
相对路径中的双属性name和type
clear_button = driver.find_element_by_xpath("//input[@name=‘continue‘][@type=‘button‘]")
相对路径中前id属性后index
clear_button = driver.find_element_by_xpath("//form[@id=‘loginForm‘]/input[4]")
There are also a couple of very useful Add-ons that can assist in discovering the XPath of an element:
continue_link = driver.find_element_by_link_text(‘Continue‘)
continue_link = driver.find_element_by_partial_link_text(‘Conti‘)
heading1 = driver.find_element_by_tag_name(‘h1‘)
content = driver.find_element_by_class_name(‘content‘)
content = driver.find_element_by_css_selector(‘p.content‘)
标签:des style http color strong os
原文地址:http://www.cnblogs.com/hugh007/p/3853509.html