| id定位: find_element_by_id() | <input id="kw" name="wd" class="s_ipt" value="" maxlength="255"autocomplete="off"> |
id="kw" |
| name定位: find_element_by_name() | <input id="kw" name="wd" class="s_ipt" value="" maxlength="255"autocomplete="off"> |
name="wd" |
| class定位:find_element_by_class_name() | <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off"> |
class="s_ipt" |
| tag定位:find_element_by_tag_name() | <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off"> |
by_tag_name('input') |
| link定位:find_element_by_link_text() | <a href="http://news.baidu.com" name="tj_trnews" class="mnav">新闻</a> |
by_link_text('新闻') |
| partial_link定位:find_element_by_partial_link_text() | <a href="http://news.baidu.com" name="tj_trnews" class="mnav">新闻</a> | by_partial_link_text('闻') |
| xpath定位:find_element_by_xpath() | <input id="kw" name="wd" class="s_ipt" value="" maxlength="255"autocomplete="off"> |
by_xpath("//*[@id='kw']") |
| CSS定位:find_element_by_css_selector() | <input id="kw" name="wd" class="s_ipt" value="" maxlength="255"autocomplete="off"> |
by_css_selector('#kw') |
1.查看页面元素两种方法
- 用谷歌浏览器打开百度首页,点击右上角--->更多工具--->开发者工具,就可以看到整个页面的html代码了
- 点击框中左上角的箭头图标,移动鼠标到百度搜索框,就可以自动定位到百度搜索框的HTML代码了,查看到搜索框的属性
- 谷歌浏览器打开百度首页,点击右键--->检查