写在前面
之前写过一篇文章提到了xpath元素定位,只写了一些函数,但是不够具体。于是想再写一篇关于xpath元素的定位终极篇,相信你一定能在这里找到你需要的解决办法。
第一种方法:
通过绝对路径方式定位(相信大家不会使用这种方式)
@H_301_11@By.xpath("html/body/div/form/input")
第二种方法:
通过相对路径方式定位
@H_301_11@By.xpath("//input")
第三种方法:
通过元素索引定位
@H_301_11@By.xpath("//input[4]")
第四种方法:
@H_301_11@By.xpath("//input[@id='kw1']")
By.xpath("//input[@type='name' and @name='kw1']")
第五种方法:
@H_301_11@By.xpath("//input[start-with(@id,'nice')
By.xpath("//input[ends-with(@id,'很漂亮')
By.xpath("//input[contains(@id,'那么美')]")
第6种方法:
使用xpath轴(未曾使用)