Selenium Webdriver——Xpath轴定位

1.following-sibling 选择当前元素后的兄弟元素

html如下:

<div class="controls">
  <div class="qcbox qcity" style="z-index: 40;">
    <div class="qunar-qcbox">
      <div class="qcbox-placeholder" style="width: 160px; left: 35px; padding-left: 0px; height: 35px; line-height: 35px; display: none;">输入国家/城市/机场</div>
      <div class="qcbox-prefix">出发</div>
      <div class="qcbox-info">
        <b></b>
      </div>
      <input class="cinput textbox" type="text" spellcheck="false" x-webkit-speech="x-webkit-speech" autocomplete="off" data-qcbox-hotcity="flight" data-qcbox-suggest="flight-fromcity" data-qcbox-prefix="出发" data-qcbox        -placeholder="城市名" name="fromCity" value="" style="left: 32px;" data-detect-oninput="1">
      <div class="qcbox-fixed"></div>
    </div>
    <div class="qsuggest-contaier js-suggestcontainer">
  </div>
</div>

follwing-sibling后需接::具体的兄弟标签

只列出第一个

要定位出发的输入框,可以发现跟text=出发的兄弟元素input就是

2.following 选择当前元素结束标签后的所有元素

follwing后需接::

下图列出了所有出发之后所有的input标签

这里只需要第一个

时间: 2024-08-04 02:08:13

Selenium Webdriver——Xpath轴定位的相关文章

Selenium Webdriver——Xpath轴定位(preceding)

 1.preceding-sibling 选取当前节点之前的所有同级节点 text=出发之前的同级节点: 2.preceding 选取当前节点开始标签之前的所有节点 text=出发节点标签之前的所有input标签节点

selenium webdriver XPath的定位方法练习 !

html  代码: <html> <body> <div id="div1"> <input name="divl1input"></input> <a href="http://www.sogou.com/">搜狗搜索</a> <img alt="div1-img1 "src="http://www.sogou.com/ima

selenium webdriver 表格的定位方法练习

selenium webdriver 表格的定位方法 html 数据准备 <html> <body> <div id="div1"> <input name="divl1input"></input> <a href="http://www.sogou.com/">搜狗搜索</a> <img alt="div1-img1 "src=&qu

【Selenium WebDriver】元素定位函数 FindElement

定位Web页面上的元素,用FindElement函数,它可以根据元素的不同属性来快速定位.具体的属性如下: 例子: HTML页面文件: 1 <html xmlns="http://www.w3.org/1999/xhtml" lang="en-us"> 2 <head> 3 <body> 4 <form name="loginForm"> 5 <label for="username

[selenium webdriver Java]元素定位——findElement/findElements

策略 语法 语法 描述 By id driver.findElement(By.id()) driver.findElements(By.id()) 通过id属性定位元素 By name driver.findElement(By.name()) driver.findElements(By.name()) 通过name属性定位元素 By class name driver.findElement(By.className()) driver.findElements(By.className(

PhantomJS + Selenium webdriver 总结-元素定位

webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要高些,使用id,name属性定位元素是最可靠,效率最高的一种办法. 1.元素定位的方法:find_element() 与find_elements() find_element() 该方法返回基于指定查询条件的webElement对象,或抛出不符合条件的异常  eg:element = driver.find_element(By.ID,'u1') fin

xpath 轴定位表达方式

xpath的使用基本语法: 1.// 从根节点开始,查找对象是全文. 2./ 从当前标签的路径开始查找 3.text()获取当前路径下的文本 [email protected]+类名或者id名 查找类名或者id的名字 5. .一个点表示当前节点 (1)获取某个标签的内容 (2)根据标签属性来查找指定的标签,获取指定标签的属性 (3)找指定的文本内容 (4)获取指定id名字的标签的文本 (5)获取指定类名的文本 (6)contains包含指定属性 轴运算名称: ancestor::* 表示当前节点

Selenium Webdriver元素定位的八种常用方式

在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下. 1. By.name() 假设我们要测试的页面源码如下: <button id="gbqfba" aria-label="Google Search" name="btnK" class="gbqfba"><

Selenium Webdriver元素定位的八种常用方式(转载)

转自:http://www.cnblogs.com/qingchunjun/p/4208159.html 在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方式共八种,现分别介绍如下. 1. By.name() 假设我们要测试的页面源码如下: <button id="gbqfba" aria-label="Google Search" n