以chrome打开百度首页为例,按f12
右侧可到想要定位的输入框元素的信息
<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
下面就依次写一下8种元素定位方式,以及使用python的写法
<a href="http://news.baidu.com" name="tj_trnews" class="mnav">新闻</a>
find_element_by_link_text(‘新闻’)
<a href="http://news.baidu.com" name="tj_trnews" class="mnav">新闻</a>
find_element_by_partial_link_text(‘新’)
7.xpath
chrome有自带的调试工具,按下f12,按照下图步骤,可直接获取xpath
find_element_by_xpath(’//*[@id=“kw”]’)
其他详细的xpath语法,参考:http://www.w3school.com.cn/xpath/index.asp
8.css selector 同上面获取xpath方法,copy selector find_element_by_css_selector(’#kw’)