元素定位一共有八种方法:
1. id定位
find_element_by_id()
页面元素里有一个且唯一的id="login",如下面:

可以定位到【登录】按钮的方法有
①、driver.find_element_by_id(‘login’)
②、driver.find_element_by_css_selector(‘#login’)
③、driver.find_element_byxpath("//*[@id='login']")
2. name定位
find_element_by_name()
如下图:

driver.find_element_name('button')
3. class_name
class标准属性,不唯一,通常找一类元素
<div class='cheese'><span>Cheddar</span></div>

4. tag_name
tag名如果是唯一的,可以根据tag定位
如果html有如下:
<iframe src='...'></iframe>
ele=driver.find_element_by_tag_name('iframe')
eles=driver.find_elements_by_tag_name('iframe')
如下图,可以通过iframe定位到输入框

5.通过链接文本选择元素
对于链接,可以通过链接其链接文本的内容
比如百度的新闻链接

6.partial_link
甚至通过部分链接文本选择元素
ele=driver.find_element_partial_link_text('123')

7.xpath定位
find_element_by_xpath()
通过//div//p可以查找任意div节点下面的p节点,无论p节点是否是直属节点
eles = food.find_elements_by_xpath('//div//p')

8.CSS定位
find_element_by_css_selector(‘div > *’)
