selenium常见元素定位方式

1、针对UI自动化测试,最基础的内容是:元素定位。只有定位到了元素后,才能对其进行相应的操作

2、那么我们常见的几种定位方式有哪些呢

  1. by id

  JS写法:document.getElementById("serviceCode");

  selenium写法:driver.find_element_by_id("serviceCode")

  2. by name 

  JS写法:document.getElementsByName("serviceCode")[0]

  selenium写法:driver.find_element_by_name("serviceCode")

  3. by Link、by partial_link、by Tag、by class不写  

3、说了这么多,似乎还没有写怎么查看页面元素:打开网页,按F12->Elements

原文地址:https://www.cnblogs.com/nieliangcai/p/12917569.html