<a href="http://tieba.baidu.com" name="tj_trtieba" class="mnav">贴吧</a>
driver.find_element_by_xpath('//a[text()="贴吧"]').click()
driver.find_element_by_xpath('//a[@href="http://tieba.baidu.com"]').click()
driver.find_element_by_xpath('//a[contains(text(),"贴")]').click()
driver.find_element_by_link_text('贴吧').click()
driver.find_element_by_partial_link_text('贴').click()
driver.find_element_by_xpath('/html/body/div/div/div/div[3]/a[5]').click()
driver.find_element_by_css_selector('#u1 > a[name="tj_trtieba"]').click()
driver.find_element_by_xpath('//a[contains(@name,"tj_trtieba")]').click()
driver.find_element_by_xpath('//a[starts-with(@name,"tj_trtieba")]').click()
注意:
1、不同的浏览器可能效果不一样,比如你用Chrome浏览器使用contains 能够定位到元素,使用IE 可能定位不到;
2、不同的xpath 版本可能不支持全部,之前遇到过定位某个元素,使用starts-with 定位不到,换成contains就定位到了;(这里有时间了,深入研究一下)